开发者

Ruby on Rails: Adding a second custom view to a controller (Rails 3)

开发者 https://www.devze.com 2023-04-02 14:14 出处:网络
Rails 3: I\'m pretty new to rails and so far it\'s all gone really well but I\'m having a little trouble understanding all of this routing stuff.

Rails 3:

I'm pretty new to rails and so far it's all gone really well but I'm having a little trouble understanding all of this routing stuff. I'm now trying to ad开发者_运维问答d a second view to my controller but I don't want to use any of the show, edit, index, etc. actions.

I want to a custom name for the view and a custom action in the controller. Could someone please explain to me how to do this. And also I would really like to know how to link to it from another view using the "link_to" method.

Any help is greatly appreciated!


I often use rest and for creating custom actions and views I just use routes

  resources :news , :only => [:index] do
     collection do
        get :events
        get :hot
        get :last
      end

     member do 
       get :vote
      end

  end 

so I created 3 actions for collection of resource and 1 for resource

you can run rake routes from console and see list of routes, there are predefined helpers for every route with postfix _path. example from documentation

new_geocoder_path returns /geocoder/new
edit_geocoder_path returns /geocoder/edit
geocoder_path returns /geocoder
0

精彩评论

暂无评论...
验证码 换一张
取 消