I have model/controller called notification.
I want to make a new url so that I can access it by:
/notifications/my_new_url?id=4
and have that page go to view my_new_url.html.erb
however, it always keeps going to show
method:
This is in my routes.rb
map.resources :notifications
开发者_运维百科map.connect 'notifications/get',
:controller => 'notifications',
:action => 'show'
map.connect 'notifications/my_new_url',
:controller => 'notifications',
:action => 'my_new_url'
Please assist me...I've been stuck on this for a while
You need to map the URL to a controller and action combination. But your action can render the view. You also need need to map the specialized URLs before URLs with wildcards. So do this:
# config/routes.rb
...
map.connect 'notifications/my_new_url',
:controller => 'notifications',
:action => 'my_new_url'
map.resources :notifications
...
# app/controllers/notifications_controller.rb
...
def my_new_url
respond_to do |format|
format.html { render :my_new_url }
end
end
...
# app/views/notifications/my_new_url.html.erb
...
精彩评论