设计:路线搞砸了

时间:2014-03-27 18:40:28

标签: ruby-on-rails ruby ruby-on-rails-3 devise

我刚刚安装了设计,但默认路由&他们给我的观点都搞砸了。我在尝试访问视图时遇到了大量错误。我正在使用rails 3.2.13&最新设计(1.1.rc0)

以下是使用以下生成的用户模型(使用rails generate devise User

获得的一些错误
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :lockable, :timeoutable and :activatable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation
  # attr_accessible :title, :body
end

运行迁移后,这已添加到我的路径文件

devise_for :users

当我尝试访问sign_up页面时出现此错误

undefined method `user_registration_path' for #<#<Class:0x007f8079d87c68>:0x007f8079badc30>

以下是发生错误的视图

<h2>Sign up</h2>

<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
  <%= f.error_messages %>
  <p><%= f.label :email %></p>
  <p><%= f.text_field :email %></p>

  <p><%= f.label :password %></p>
  <p><%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %></p>
  <p><%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Sign up" %></p>
<% end %>

<%= render :partial => "devise/shared/links" %>

很明显为什么这会失败,因为这是我的佣金路线的回归

    new_user_session GET    /users/sign_in(.:format)              devise/sessions#new
        user_session POST   /users/sign_in(.:format)              devise/sessions#create
destroy_user_session GET    /users/sign_out(.:format)             devise/sessions#destroy
            password POST   /users/password(.:format)             devise/passwords#create {:name_prefix=>:user}
        new_password GET    /users/password/new(.:format)         devise/passwords#new {:name_prefix=>:user}
       edit_password GET    /users/password/edit(.:format)        devise/passwords#edit {:name_prefix=>:user}
                     PUT    /users/password(.:format)             devise/passwords#update {:name_prefix=>:user}
                     POST   /users/registration(.:format)         devise/registrations#create {:name_prefix=>"user_registration"}
                 new GET    /users/registration/sign_up(.:format) devise/registrations#new {:name_prefix=>"user_registration"}
                edit GET    /users/registration/edit(.:format)    devise/registrations#edit {:name_prefix=>"user_registration"}
                     PUT    /users/registration(.:format)         devise/registrations#update {:name_prefix=>"user_registration"}
                     DELETE /users/registration(.:format)         devise/registrations#destroy {:name_prefix=>"user_registration"}
        confirmation POST   /users/confirmation(.:format)         devise/confirmations#create {:name_prefix=>:user}
    new_confirmation GET    /users/confirmation/new(.:format)     devise/confirmations#new {:name_prefix=>:user}
                     GET    /users/confirmation(.:format)         devise/confirmations#show {:name_prefix=>:user}

显然,正确的路线是new_path

以下是我尝试访问sign_in视图的另一个错误

wrong number of arguments (3 for 2)

查看

<h2>Sign in</h2>

<%= form_for(resource_name, resource, :url => session_path(resource_name)) do |f| %>
  <p><%= f.label :email %></p>
  <p><%= f.text_field :email %></p>

  <p><%= f.label :password %></p>
  <p><%= f.password_field :password %></p>

  <% if devise_mapping.rememberable? -%>
    <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
  <% end -%>

  <p><%= f.submit "Sign in" %></p>
<% end %>

<%= render :partial => "devise/shared/links" %>

我之前使用过设计,但我不记得得到所有这些错误。到底是怎么回事?我并不认为它是开箱即用的。

1 个答案:

答案 0 :(得分:0)

要解决wrong number of arguments (3 for 2)错误,请将form_for更新为

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>  

路由应在routes.rb

中定义如下
devise_for :users

devise版本存在一些问题。我建议您使用特定版本的Devise更新Gemfile,如下所示:

gem 'devise', '~> 3.2.4'      ## instead of gem 'devise'

并运行bundle install