我有一个Rails 4应用程序设置为使用Devise,我正在运行密码重置问题.我有邮件设置,密码重置电子邮件发送正常.提供的链接具有分配给它的正确reset_password_token,我使用该数据库检查了该链接.但是,当我使用格式正确的密码提交表单时,会出现错误,指出重置令牌无效.
但是,完全相同的代码在本地工作正常rails s.电子邮件发送,我实际上可以重置密码.我使用的代码只是标准的Devise代码,我没有覆盖任何代码.
也许这与Apache有关?我不太熟悉它.有没有人有任何想法?
User.find(:all, :order => "RANDOM()", :limit => 10) 是我在Rails 3中做到的方式.
User.all(:order => "RANDOM()", :limit => 10) 是我认为Rails 4会怎么做,但这仍然给我一个弃用警告:
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`).
Run Code Online (Sandbox Code Playgroud) 出于我无法控制的原因,我无法在当前项目中使用RSpec进行测试.我正在尝试测试Devise重置密码,我似乎无法想出一些有用的东西.
这是我到目前为止所拥有的:
require 'test_helper'
class ResetPasswordTest < ActionDispatch::IntegrationTest
setup do
@user = users(:example)
end
test "reset user's password" do
old_password = @user.encrypted_password
puts @user.inspect
# This assertion works
assert_difference('ActionMailer::Base.deliveries.count', 1) do
post user_password_path, user: {email: @user.email}
end
# puts @user.reset_password_token => nil
# Not sure why this doesn't assign a reset password token to @user
patch "/users/password", user: {
reset_password_token: @user.reset_password_token,
password: "new-password",
password_confirmation: "new-password",
}
# I get a success here, but I'm not sure why, since reset password …Run Code Online (Sandbox Code Playgroud) 我有一个任务,它逐行读取一个大文件,用它做一些逻辑,并返回一个我需要写入文件的字符串.输出的顺序无关紧要.但是,当我尝试下面的代码时,它会在读取我的文件的15-20k行后停止/变得非常慢.
public static Object FileLock = new Object();
...
Parallel.ForEach(System.IO.File.ReadLines(inputFile), (line, _, lineNumber) =>
{
var output = MyComplexMethodReturnsAString(line);
lock (FileLock)
{
using (var file = System.IO.File.AppendText(outputFile))
{
file.WriteLine(output);
}
}
});
Run Code Online (Sandbox Code Playgroud)
为什么我的程序在运行一段时间后会变慢?有没有更正确的方法来执行此任务?
所以我是Objective-C的新手,我正在学习本教程.我正在运行Linux Mint 14.我已经通过运行安装了gobjc,sudo apt-get install gobjc并且我已经安装了gcc.我正在尝试他们的Point例子,但我遇到了一些奇怪的错误.
这是我的代码(几乎从网站上复制并粘贴):
#import <objc/Object.h>
#import <math.h>
#import <stdio.h>
@interface Point : Object
{
@private
double x;
double y;
}
- (id) x: (double) x_value;
- (double) x;
- (id) y: (double) y_value;
- (double) y;
- (double) magnitude;
@end
@implementation Point
- (id) x: (double) x_value
{
x = x_value;
return self;
}
- (double) x
{
return x;
}
- (id) y: (double) y_value
{
y …Run Code Online (Sandbox Code Playgroud) 对不起,如果标题有点令人困惑.我有一个Item与该领域的表格name.有一个文本字段,用户可以在其中输入名称并提交.但是如果用户没有输入任何东西并且点击提交,Rails会给我一个param not found: item错误,我不知道该解决这个问题.
items_controller.rb
def new
@item = Item.new()
respond_to do |format|
format.html
format.json { render json: @item }
end
end
def create
@item = Item.new(item_params)
respond_to do |format|
if @item.save
format.html { redirect_to items_path }
format.json { render json: @item, status: :created, location: @item }
else
format.html { render action: 'new', :notice => "Input a name." }
format.json { render json: @item.errors, status: :unprocessable_entity }
end
end
end
private
def item_params
params.require(:item).permit(:name) …Run Code Online (Sandbox Code Playgroud) 我正在做一个项目,我们需要知道我们正在使用的Nuget软件包的版本,并在代码中使用它。
我尝试的一种方法是从packages.config文件中读取信息,将其解析为所需的Package,然后解析该行以获取该版本。就像是:
var lines = System.IO.File.ReadAllLines(@"..\..\packages.config");
foreach(var line in lines)
{
if (line.Contains("My.Package"))
{
foreach(var part in line.split(' '))
{
if (part.Contains("version"))
{
return part.Split('"')[1];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有更好的方法以编程方式执行此操作?
编辑:上面的代码将不起作用,因为packages.config未随应用程序一起部署。
我有一些对象:
public class MyObject
{
public MyField Field { get; set; }
}
public class MyField
{
[JsonProperty]
public Entity MyEntity { get; set; }
public IEntity IMyEntity { get; set; }
}
public interface IEntity
{
string MyStr { get; }
}
public class Entity : IEntity
{
}
Run Code Online (Sandbox Code Playgroud)
然后我正在尝试做类似的事情
JsonConvert.DeserializeObject<MyObject>(myObjStr);
Run Code Online (Sandbox Code Playgroud)
这会引发类似于
无法创建 MyObject 类型的实例...类型是接口或抽象类,无法实例化。路径“MyField.IMyEntity.MyInt”
我无法更改字段或实体,因为它在另一个组的代码库中。MyObject 类是我的。有没有办法反序列化这个对象?我在JSON.NET 中使用 JsonSerializerSettings 尝试了一些方法- 如何反序列化接口实例的集合?但无济于事。
我正在尝试使用Poltergeist截取屏幕截图,并获取图片,但现在我想更改屏幕截图的屏幕大小.
这是我到目前为止所拥有的:
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
require 'spec_helper'
include Warden::Test::Helpers
describe 'PhantomJS' do
before do
page.driver.resize_window(1920, 1080)
@user = FactoryGirl.create(:user)
login_as(@user, :scope => :user)
end
it "should take a screenshot", :js => true do
visit root_path
page.save_screenshot('lib/screenshot.png')
end
end
Run Code Online (Sandbox Code Playgroud)
然而,这将返回1000x1437的图像.调整大小似乎没有为截图做任何事情.有谁知道调整大小为什么不影响它/如何解决它?谢谢!
c# ×3
devise ×2
.net ×1
constructor ×1
file-writing ×1
gcc ×1
json ×1
minitest ×1
nuget ×1
objective-c ×1
poltergeist ×1
random ×1