我的设置 - Rails 4,ActiveAdmin,Devise生成的用户模型.用户使用用户名进行身份验证,但没有email属性.我提到了最后一个,因为Devise严重依赖于email属性,所以这可能与问题有关.我在博客文章中描述了我的确切设置和代码.
在ActiveAdmin后端,我转到用户 - >新用户 - >填写用户名,密码,密码确认 - >创建用户.新用户表单被删除而不是创建新用户,而在密码字段下我得到错误can't be blank.当我转到Rails控制台并手动创建一个新用户时,User.create(username: 'Joe', password: 'password', password_confirmation: 'password')一切正常,用户可以登录localhost:3000/users/sign_in.
我看到了这个问题.如果我添加到我的用户模型:
def password_required?
new_record? ? false : super
end
Run Code Online (Sandbox Code Playgroud)
我可以创建一个新用户,但所有字段(包括用户名,加密密码)都是空白的.
更新正如Leger建议的那样,我发布了我的代码.当我使用Devise和Activeadmin的内置控制器时,我认为在Activeadmin和我的数据库模式中发布我的用户资源的代码是有意义的:
Activeadmin中的用户资源:
ActiveAdmin.register User do
# This determines which attributes of the User model will be displayed in the index page. I have left only username, but feel free to uncomment the rest of the lines or add any …Run Code Online (Sandbox Code Playgroud) 我不想安装整个XCode,所以我只是下载了Xcode的命令行工具.我试图通过rvm安装ruby 1.9.3.但是,rvm抱怨没有选择xcode:
xcode-select:错误:未选择Xcode.使用xcode-select -switch,或查看xcode-select手册页(man xcode-select)以获取更多信息.
我读了xcode-select手册页,我知道如何设置xcode命令行工具的路径,但我不知道它们的安装位置.我怎么找到这个?
我正在使用OS X Mountain Lion.
public_send我知道调用而不是对象调用是一个很好的做法send,以免无意中调用私有方法。但是,如果我知道我要调用的方法肯定是公共的,我可以使用 send 吗?我写了这段代码:
[:name, :artist, :album,].each do |attribute|
define_method "#{attribute}s" do
@songs.map { |song| song.public_send(attribute) }.uniq
end
end
Run Code Online (Sandbox Code Playgroud)
public_send如果我用send这里替换,会被认为是不好的做法吗?
假设你有这个数组:
arr = w|one two three|
Run Code Online (Sandbox Code Playgroud)
如何通过将两个连续元素作为块参数进行迭代,如下所示:
1st cycle: |nil, 'one'|
2nd cycle: |'one', 'two'|
3rd cycle: |'two', 'three'|
Run Code Online (Sandbox Code Playgroud)
Sofar我只来这里:
arr.each_index { |i| [i - 1 < 0 ? nil: arr[i - 1], arr[i]] }
Run Code Online (Sandbox Code Playgroud)
更好的解决方案?有类似的东西each(n)吗?
在pgAdmin III中,您可以:
如果必须为多个表执行此操作,是否有办法将脚本组合在一个文件中(除了手动复制粘贴它们)?如果这可以通过psql提示符或phppgadmin完成,那也可以.
如果我有课:
class KlassWithSecret
def initialize
@secret = 99
end
end
Run Code Online (Sandbox Code Playgroud)
并运行:
puts KlassWithSecret.new.instance_eval { @secret }
Run Code Online (Sandbox Code Playgroud)
它打印99,但如果我运行:
puts KlassWithSecret.new.instance_eval do
@secret
end
Run Code Online (Sandbox Code Playgroud)
它返回一个错误: `instance_eval': wrong number of arguments (0 for 1..3) (ArgumentError)
为什么我不能使用do/end块instance_eval?
PS我正在使用Ruby 2.1.0.
我们如何解析Ruby中的json文件?
require 'json'
JSON.parse File.read('data.json')
Run Code Online (Sandbox Code Playgroud)
如果文件非常大并且我们不想立即将其加载到内存中该怎么办?那我们怎么解析呢?
在解决方案资源管理器的VS 2012中,我右键单击解决方案 - >添加 - >新项.在列表中,我看到不同的项目,如文本文件,网页,样式表,但没有.js项目.到目前为止,我唯一的方法是在记事本++中创建它,保存它然后将其添加为现有项目.有更快的方法吗?
谢谢.

如果我有这样一个字符串'Lorem Ipsum',我需要一种方法,它返回字符串的随机部分,如'rem I','Lor'等(UPDATE:该方法不应返回空字符串).到目前为止,我已经想出了这个:
def random_slice string
start = rand string.size - 2
finish = rand start + 1..string.size - 1
word[start..finish]
end
Run Code Online (Sandbox Code Playgroud)
还有更好的选择吗?
是否有扩展名或设置可以使.diff在 VS Code 中打开的具有扩展名的文件将添加的行显示为绿色,删除的行显示为红色?目前,当我打开 diff 文件时,它会以相同的颜色显示添加和删除的行。我正在使用 VS Code 版本:1.37.1。
PS 我尝试了diff 扩展,但它对我不起作用。
PPS 我尝试在禁用扩展的情况下重新加载 VS Code,但突出显示仍然损坏:
ruby ×6
activeadmin ×1
arrays ×1
coding-style ×1
devise ×1
javascript ×1
json ×1
loops ×1
methods ×1
pgadmin ×1
phppgadmin ×1
postgresql ×1
psql ×1
random ×1
rvm ×1
slice ×1
string ×1
syntax ×1
xcode ×1