Tag: 装饰

在不同的视图中设计forms“未定义的方法`’为nil:NilClass”

所以我试图在不同的控制器中做与Deviseforms完全相同的事情 在另一页上准确设计登录表单 我有一个辅助模块 def resource_name :user end def resource @resource ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end 但我得到nil的未定义方法`[]’:NilClass就行了 true %> 我在views / devise / sessions / new.html.erb中添加了 我在Home#index #User中初始化时遇到RuntimeError Sign in resource_name, :url => user_session_path(resource_name)) do |f| %> true %> 我也尝试过这个辅助模块 def resource_name :user end def resource @resource = User.new end def devise_mapping […]

用户会话超时后无法立即登录(Devise Gem)

我遇到的问题是,如果我的用户会话超时(使用设计gem),我将尝试转到另一个屏幕,它将带我回到正确的登录页面。 但是,url不会从我尝试前往超时之前的页面更改。 所以例如,会话将结束,但如果那是我在超时之前的标题,我仍然会被带到这里: http://localhost:3000/users/edit 这个问题是它不允许我登录,直到我刷新页面 – 这改变了url: http://localhost:3000/users/sign_in 。 有任何想法吗? 编辑 : 该日志表示同一会话的两个不同浏览器选项卡。 前两段显示用户注销,最后两段显示当用户(看起来仍然在第二个选项卡上登录)尝试转到其他页面时的样子。 主要区别在于日志没有显示第二个选项卡的“Started GET”/ projects / messageChannel“”。 但是当我点击刷新时它会出现。 服务器日志如下: Started GET “/” for XXXXXXX at 2014-06-18 10:09:53 -0400 Processing by Devise::SessionsController#new as HTML Rendered layouts/_messages.html.erb (0.1ms) Rendered devise/sessions/new.html.erb within layouts/application (2.6ms) Rendered layouts/_navigation.html.slim (0.4ms) Completed 200 OK in 11ms (Views: 10.1ms | ActiveRecord: […]

在失败的注册时,Rails设计重定向到’/ users’而不是’/ users / sign_up’

我一直在寻找解决这个问题 – 当用户使用Devise创建注册失败时,无论出于何种原因,他们都会被重定向到’/ users’而不是留在’/ users / sign_up’并持续存在错误: 这是我的路线: devise_for :users, controllers: { sessions: ‘users/sessions’, confirmations: ‘users/confirmations’, registrations: ‘users/registrations’, passwords: ‘users/passwords’, invitations: ‘users/invitations’ }, sign_out_via: [:get, :delete] 和/users/registrations_controller.rb class Users::RegistrationsController < Devise::RegistrationsController prepend_before_filter :require_no_authentication, only: [:new, :create] def new @body_class = "hold-transition register-page" build_resource({}) yield resource if block_given? respond_with resource end def create build_resource(sign_up_params) resource.save yield […]

强参数 – 设计3.0.0和Rails 4.“未允许的参数:名称”

我目前正在使用Rails 4和Devise 3.0.0。 我试图在注册表单中添加“名称”的自定义字段并编辑注册表单。 每当我提交表单时,都会出现以下错误: Unpermitted parameters: name WARNING: Can’t mass-assign protected attributes for User: email, password, password_confirmation. 我知道这与Rails 4处理参数的方式有关,但我不明白我现在应该怎么做。 我已经四处搜索并看到我应该在涉及“params”的User模型中添加一些行。 我的用户模型目前看起来像这样: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, #:recoverable, :rememberable, :trackable, :validatable attr_accessible :name, :password, :password_confirmation, :remember_me, :email end 根据Rails 4中如何使用attr_accessible? ,我应该将以下代码添加到“控制器”。 class PeopleController < ApplicationController def create Person.create(person_params) end private def person_params params.require(:person).permit(:name, […]

Rails添加了新的视图来设计

我安装了devise之后用这个命令生成了视图 rails generate devise:views 我覆盖了注册控制器 class RegistrationsController < Devise::RegistrationsController def sign_up2 end end 并更新routes.rb devise_for :users, :controllers => { :registrations => “registrations” } 我期待看到一个新的路线/视图 /users/sign_up2 但我没有看到它和这里的路线设计 new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) […]

生成模型后Ruby gem设计错误

我从昨天开始就一直坚持这个问题,我已经在互联网上搜索了,看来很多人在运行’rails generate devise User’之后也遇到了同样的错误 我正在运行我认为是最新版本的Devise(3.0.0.rc),当我尝试运行’rails server’时,我收到以下错误消息。 (我遵循安装时设计给出的规定) 我无法破坏模型,我无法迁移我的数据库,我必须删除整个项目,每次都重新开始。 请帮忙! C:\Sites\blogbar>rails server => Booting WEBrick => Rails 4.0.0 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/act ive_support/dependencies.rb:228:in `require’: cannot load such file — 1.9/bcryp t_ext (LoadError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 4.0.0/lib/active_support/dependencies.rb:228:in `block in require’ […]

Rails 4 – devise_for不使用自定义控制器

我在我的Rails应用程序中使用Devise,我想自定义它的一些行为。 我已经阅读了devise_for的文档。 但我无法使用我的自定义控制器。 我的溃败看起来像这样: devise_for :users, controllers: { sessions: “users/sessions”, registrations: “users/registrations” } 在我的Users::RegistrationsController < Devise::RegistrationsController我尝试了以下内容: # POST /resource def create puts “I’m here” # never happens! super end 关于我缺少的任何想法? 更新 这是我的文件结构: 更新2 想想我可能找到了问题的根源。 我在一个Bootstrap模式中渲染并呈现我的注册表单,而不是默认的Devise路径。 我在这条路上提出表格: /apps/1/edit 并不是: users/sign_up 如果我在这条路径上注册users/sign_up就可以了,我的方法users/sign_up被调用。 在我的/apps/1/edit视图中,我提供了这样的表单: = render “users/registrations/modal_form” 我的apps_controller编辑操作(我提交注册表单的操作)当前是空的: # GET /apps/1/edit def edit end 我的users/registrations/modal_form部分的相关部分如下所示: .modal.fade#registrations_modal{ tabindex: -1, […]

检查nil给出错误

我的控制器中有这一行: user = User.any_of({:user_name => login}, {:email => login}) if user.nil? # … elsif user.legacy_password.nil? 它会产生这个错误: undefined method `legacy_password’ for []:Array 为什么会这样? 用户对象应该是nil 。 至少这是调试器所说的。

从_form或controller保存的当前用户ID

我正在使用Devise来管理用户,我的目标是使用创建的记录保存当前用户。 我试图将当前用户保存在控制器或_form中,但无论哪种方式都失败了! 感谢大家的帮助。 我的记录模型 class Record < ActiveRecord::Base #Associations belongs_to :user # Validations validates :title, :user, presence: true end 我的记录控制器 class RecordsController < ApplicationController before_action :find_record, only: [:show, :edit, :update, :destroy] def create @record = Record.new(record_params) if @record.save redirect_to @record else @records = Record.all render 'index' end end def update if @record.update(record_params) flash[:notice] = "The […]

覆盖DeviseController基类–Rails 4,Devise 3

我试图覆盖Devise方法set_flash_message 。 设计文档介绍了如何覆盖各个子模块的控制器 。 但是,这个特殊的方法位于DeviseController ,它是所有模块的父类。 文档(包括wiki和inline)都没有说明如何实现这一点,所以我不确定如何最好地继续。 我相信最好的方法是简单地重新打开类并根据需要修改方法,然后在/lib放置一个文件。 然而,似乎在Devise之前加载,导致错误喷出。 NameError in Devise::RegistrationsController#new undefined local variable or method `require_no_authentication’ for # DeviseController的复杂父定义也可能具有净负面影响: class DeviseController < Devise.parent_controller.constantize 思考?