Button_to没有路由匹配[GET]“/ new_user_path”

时间:2013-10-03 23:27:37

标签: ruby-on-rails ruby routes button-to

我正在尝试使用users/new将页面定向到目录button_to 但是每次我点击它都会产生错误

  

路由错误

     

没有路线匹配[GET]“/ new_user_path”

这是我的application.html.haml,其中包含我正在谈论的button_to

%html

%head
%title Rotten Potatoes!
= stylesheet_link_tag 'application'
= javascript_include_tag 'application'
= csrf_meta_tags


%body
%h1.title Rotten Potatoes!

= button_to 'Sign Up/Login', 'new_user_path', :method => :get

#main
  - if flash[:notice]
    #notice.message= flash[:notice]
  - elsif flash[:warning]
    #warning.message= flash[:warning]

  = yield

以下是我的rake routes

的结果
    movies   GET    /movies(.:format)           movies#index
             POST   /movies(.:format)           movies#create
   new_movie GET    /movies/new(.:format)       movies#new
  edit_movie GET    /movies/:id/edit(.:format)  movies#edit
       movie GET    /movies/:id(.:format)       movies#show
             PUT    /movies/:id(.:format)       movies#update
             DELETE /movies/:id(.:format)       movies#destroy
       users GET    /users(.:format)            users#index
             POST   /users(.:format)            users#create
    new_user GET    /users/new(.:format)        users#new
   edit_user GET    /users/:id/edit(.:format)   users#edit
        user GET    /users/:id(.:format)        users#show
             PUT    /users/:id(.:format)        users#update
             DELETE /users/:id(.:format)        users#destroy

如果有帮助,这是我的users_controller.rb文件

class UsersController < ApplicationController

  def new
  end

  def create
  @user=User.create_user!(params[:user])

      if !!(@user)
      flash[:notice] = "New user #{@user.user_id} was successfully created."
      redirect_to movies_path
    else
      flash[:notice] = "The User Id #{params[:user][:user_id]} already exists"
      redirect_to new_user_path
    end
  end

end

请注意redirect_to new_user_path(带条件语句)完全正常。

你能告诉我问题出在哪里吗?此外,我也尝试使用link_to,但仍然失败。

1 个答案:

答案 0 :(得分:1)

button_to的参数应该是方法new_user_path()而不是字符串'new_user_path'吗?