Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 试着学习rails并不断地学习noMethodError_Ruby On Rails - Fatal编程技术网

Ruby on rails 试着学习rails并不断地学习noMethodError

Ruby on rails 试着学习rails并不断地学习noMethodError,ruby-on-rails,Ruby On Rails,我已经完成了rails入门教程,现在我正在尝试使用Desive gem设置另一个项目进行身份验证。基本上我想要的就是有一个主页,一个用户可以填写表单进行注册的页面,然后是一个进行身份验证的安全页面 现在我在导航到注册页面时遇到问题。以下是我收到的错误: NoMethodError in Signup#index Showing /Users/tomcaflisch/Sites/project2/app/views/signup/_form.html.erb where line #1 rais

我已经完成了rails入门教程,现在我正在尝试使用Desive gem设置另一个项目进行身份验证。基本上我想要的就是有一个主页,一个用户可以填写表单进行注册的页面,然后是一个进行身份验证的安全页面

现在我在导航到注册页面时遇到问题。以下是我收到的错误:

NoMethodError in Signup#index

Showing /Users/tomcaflisch/Sites/project2/app/views/signup/_form.html.erb where line #1 raised:

undefined method `users_path' for #<#<Class:0x007fa734b3e510>:0x007fa734b3a910>

Extracted source (around line #1):

1: <%= form_for(@user) do |f| %>
2:  <% if @user.errors.any? %>
3:  <div id="errorExplanation">
4:      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this post from being saved: </h2>
$bundle exec rake routes | grep用户:

    new_user_session GET    /users/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)       {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)      {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)  {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)      {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)        {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)               {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)       {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)          {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)               {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)               {:action=>"destroy", :controller=>"devise/registrations"}

因为您正在创建自己的注册控制器,我相信Desive routes并不是在您喜欢的地方进行路由
发布您的路线文件,让我们看看是否可以理顺您的路线。

它正在寻找
注册#索引。。它应该寻找
SignupController#index

在您的routes.rb中,您希望

root :to => 'signup#index'
另外,
undefined method users\u path
缺少获取用户的路径,或者很可能缺少来自您的routes.rb的
resources:users

对于新用户,您需要类似于(user.new)
form\u,它将点击
userscocontroller\new

__

还是这样做

(一)

对于所需的
视图/users/new.html.erb

<%= form_for(@user) do |f| %>
  <%= render 'fields', :f => f %>
  ....

看起来您混合了两件事:Deavise提供了自己的注册页面,您还创建了自己的注册页面

有时候这是合适的,但是很多时候默认的Desive页面已经足够好了——或者至少已经足够好了

我建议您首先尝试使用Desive自己的页面实现Desive,暂时不要使用登录和注册页面。你看不到设计页面,因为它们隐藏在宝石里

如果要自定义它们,可以通过以下步骤在项目中安装Desive页面(以haml格式):


您能否发布运行
bundle exec rake routes | grep user
时得到的信息。我很想知道你的设计路线是否被正确创建。谢谢!我已经根据你发布的内容在下面添加了一个答案。我实际上没有UsersController。我只有一个索引控制器、注册控制器和../models/user.rb。我需要一个用户控制器吗?索引控制器没有意义(从名称来看)使用页面控制器可能就是为了这个。要创建\编辑\删除用户,您需要为用户设置控制器。form_for正在寻找类似我没有深入阅读Desive文档的信息。
get "signup/index"
devise_for :users
get "index/index" 
root :to => 'index#index'
    new_user_session GET    /users/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)       {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)      {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)  {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)      {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)        {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)               {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)       {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)          {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)               {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)               {:action=>"destroy", :controller=>"devise/registrations"}
root :to => 'signup#index'
<%= form_for(@user) do |f| %>
  <%= render 'fields', :f => f %>
  ....
 def new
    @user = User.new
    ..
  end