Basic Ruby on Rails Routing Question

I have a controller without any related model. This controller should cover some information from different models. I have many actions that define certain views on a page. What would be the best way to organize routes for this controller?

What I would like is to have / dashboard / something point to any action in the control panel controller. Not actions like new / edit, but arbitrary actions (showstats, etc.).

With trial and error, I did something like this:

map.dashboard 'dashboard/:action', :controller => 'dashboard', :action => :action

You can now access these URLs using the helper:

dashboard_url('actionname')

This approach seems to work fine, but is it? I don’t quite understand how helper method names are generated. How to generate the same helper names as in the base action_controller_url controllers? This will be more general and make the code more consistent.

Thanks in advance.

+5
source share
3 answers

You do not need to indicate the key :action => :actionon the route, this is already done for you. In addition, as you did, everything is in order.

You can also specify it as a symbol: dashboard_url(:actionname)but you already knew that;)

+5
source

, , :

map.example_dashboard 'dashboard/example', :controller => 'dashboard', :action => 'example'
map.another_dashboard 'dashboard/another', :controller => 'dashboard', :action => 'another'

_url _path . , .

+2

How to generate the same helper names as in the base action_controller_url controllers?

  map.action_controller(
    'action_controller',
    :controller => 'controller',
    :action => 'action',
    :conditions => { :method => :get }  # You can restrict the HTTP reqs allowed
  )
0
source

All Articles