控制器与轨道视图之间的连接

时间:2013-02-27 21:36:15

标签: ruby-on-rails view controller connection

users_controller.rb 中,我有我的方法:

def showallusers
 @users = User.all

 respond_to do |format|
  format.html  # showallusers.html.erb
  format.json  { render :json => @users }
 end
end

并在 app / views / users 我有 showallusers.html.erb ,其中包含:

<p>test</p>

但是当我输入

 http://localhost:3000/users/showallusers

在浏览器中,它会显示 show.html.erb

我的 routes.rb

  resources :users

  resources :projects do
    resources :issues  
  end

  #resources :issues

  resources :projects

  resources :sessions


  root :to => "users#index"

  match "/auth/:provider/callback" => "sessions#create"
  match "/signout" => "sessions#destroy", :as => :signout

您知道吗,出了什么问题,我该如何解决?感谢

1 个答案:

答案 0 :(得分:1)

在您的routes.rb中:

resources :users do
  collection do
    get :showallusers # why not :show_all_users? Isn't it more readable?
    # you may also need
    # post :showallusers
  end
end

然后重新启动服务器以确保生成新的url-helpers(新助手应为showallusers_users_path