我是Devise的新手,并通过使用电子邮件地址作为身份验证密钥使其工作正常.但是,我有一个用例需要用户名,而我似乎无法使用它.
我已经在users表中添加了一个字符串列"username",将字段从:email更改为:登录表单中的:username,并将devise.rb中的身份验证密钥更改为:username但是当我转到登录我遇到了这个提示:"请输入一个电子邮件地址".
我究竟做错了什么?
**new.html.erb**
<div><%= f.label :username %><br />
<%= f.email_field :username %></div>
**User.rb**
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:username]
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :username
# attr_accessible :title, :body
end
**devise.rb**
config.authentication_keys = [ :username ]
Run Code Online (Sandbox Code Playgroud) 我遇到了这个C#文字,并想知道它是什么意思?
特别是在以下情况中:
string.Format("{0:x}", byteArray[i]);
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在使用Rails 3.2和ActiveAdmin 0.4.4开发一个应用程序.我的模型名为Teaser(/app/models/teaser.rb):
class Teaser < ActiveRecord::Base
attr_accessible :img, :name, :url
validates :img, :name, :presence => true
mount_uploader :img, TeaserUploader
end
Run Code Online (Sandbox Code Playgroud)
我添加了ActiveAdmin(/app/admin/teaser.rb):
# encoding: UTF-8
ActiveAdmin.register Teaser do
form do |f|
f.inputs "Teaser" do
f.input :name, :label => '?????'
f.input :url, :label => '??????'
f.input :img, :as => :file, :label => '????????'
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
现在,当我去'http:// localhost:3000/admin/teasers'时,我收到以下错误:
显示C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb第1行引发:收集不是分页范围.在调用之前设置collection.page(params [:page]).per(10):paginated_collection.
当我在linux上测试我的应用程序时,我得到了同样的错误(Ubuntu 12.04).
我可以通过这种方式解决这个问题(/app/admin/teaser.rb):
# encoding: UTF-8
ActiveAdmin.register Teaser, :as => 'Somename' do
Run Code Online (Sandbox Code Playgroud)
但是如果我使用这种方法,我就无法使用/app/config/locales/XX.yml来翻译这个模型
所有其他模型都正常工作.
我的设备ID是:358313044737548
和
我的android id是:4e4c5141b7cb261e
有人可以解释一下这两者之间的区别和各自的目的吗?
谢谢
有没有办法从它的Github仓库(或更具体地说,一个分支)而不是从Rubygems安装Ruby gem?
我试过了
gem_package 'some_gem' do
source 'git://github.com:user/some_gem.git'
end
Run Code Online (Sandbox Code Playgroud)
我明白了
Gem::Exception
--------------
Cannot load gem at [git://github.com:user/some_gem.git] in /
Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/some_recipe/recipes/default.rb
15: gem_package 'some_gem' do
16: source 'git://github.com:user/some_gem.git'
17: end
18:
Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/some_gem/recipes/default.rb:15:in `from_file'
gem_package("some_gem") do
provider Chef::Provider::Package::Rubygems
action :install
retries 0
retry_delay 2
package_name "some_gem"
source "git://github.com:user/some_gem.git"
cookbook_name :some_cookbook
recipe_name "default"
end
Run Code Online (Sandbox Code Playgroud)
我也尝试了同样https://github.com/user/some_gem的错误来源Illformed requirement [""].
我计划进行后台服务,这将使屏幕闪烁/闪烁,直到用户触摸屏幕.
我不知道如何使屏幕闪烁的方法 - 只有通过生成活动可以通过亮度和控制来学习的方法.
想要在屏幕上进行闪烁换色,即黑白或屏幕开/关,使其比亮度更明显.
我正在使用datepicker在我的表单上插入日期,当然这会将日期作为字符串返回给控制器.问题是当我尝试将此字符串转换为日期时,我收到错误"无效日期"
Date.parse(params[:abc][:date])
为了验证我是否正确,我编写了以下ruby程序:
string_date = "06/18/2011"
date = Date.parse(string_date)
puts date
这完全没问题.但是当我在rails控制器中尝试相同的操作时,它会给出无效的日期错误.
请帮忙.
我在这里找到了一个API
但是,当我运行AndroidSample测试应用程序时,我会收到错误.
当我按下"获取打印机状态"按钮时,我得到"打印机在线".看起来这个按钮很有效.
然而:
按"从打印机读取数据"会产生"失败.无法读取固件名称".
按"打印收据"会导致应用程序挂起3秒钟.然后没事.
按"打印已检查的块收据"会产生"打印成功"或大挂起(有时强制关闭).无论如何,什么都没有打印出来.
我有一个寻找帖子的简单邮政路线_id.问题是pathFor助手创建了这样的路径:
ObjectID("52e16453431fc2fba4b6d6a8")
Run Code Online (Sandbox Code Playgroud)
我猜mongoDB插入已被更改,现在该_id对象在其中包含另一个对象调用_str.
这是我的路线:
this.route("post", {
path: "/post/:_id",
waitOn:function(){
NProgress.start();
Meteor.subscribe("Teams");
},
before: function () {
NProgress.done();
},
data: function () {
return Posts.findOne({_id: this.params._id});
}
});
Run Code Online (Sandbox Code Playgroud)
目前,它创建了一个href像:
post/ObjectID("52e16453431fc2fba4b6d6a8")
Run Code Online (Sandbox Code Playgroud)
点击它打开一个网址
post/ObjectID("52e16453431fc2fba4b6d6a8")
Run Code Online (Sandbox Code Playgroud)
但是,我得到了"NotFound"模板而不是帖子.
我怎样才能解决这个问题?
我使用rails 4.0.1和ruby 2.0.0 with devise 3.2.2.当用户尝试编辑他的帐户时,我不断收到此问题.我在application_controller.rb中有我的强参数和一个自定义更新控制器,如下所示:
class RegistrationsController <Devise :: RegistrationsController
def update
# For Rails 4
account_update_params = devise_parameter_sanitizer.for(:account_update)
@user = User.find(current_user.id)
@user.balanced_associate_token_with_customer(account_update_params)
if @user.update_with_password(account_update_params)
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
Run Code Online (Sandbox Code Playgroud)
protected def after_update_path_for(resource)user_path(resource)end end
从昨天开始我一直在拉我的头发......任何帮助都会受到赞赏.如果您需要更多信息,请告诉我.
编辑:在我注意到错误之前唯一改变的是设计开始在设计初始化文件中请求config.secret_key.
完整跟踪的一部分显示:
devise (3.2.2) lib/devise/models/database_authenticatable.rb:64:in `[]'
devise (3.2.2) lib/devise/models/database_authenticatable.rb:64:in `update_with_password'
app/controllers/registrations_controller.rb:12:in `update'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'
Run Code Online (Sandbox Code Playgroud)
谢谢!
ruby ×4
android ×3
devise ×2
activeadmin ×1
c# ×1
chef-infra ×1
date ×1
gem ×1
git ×1
github ×1
iron-router ×1
javapos ×1
meteor ×1
mongodb ×1
printing ×1
receipt ×1
ruby-1.9.2 ×1
rvm ×1
spree ×1
stario-sdk ×1