views:

239

answers:

1

I have added into my routes file prefix value to each map.resources line. So it all looks like this:

map.resources :subjects, :path_prefix => ':company'

I have even added this line for default behavior

map.connect ':company/:controller/:action/:id'

which is not necessary (I believe) because all the routes are handled with resources method.

I fetch the :company param in my before_filter method in ApplicationController. Everything works. But.

Is it possible to change the behaviour of all *_path methods that it would set company value for all generated urls by default with the one taken from the url? To make it work perfectly I would have to add company value as param for each _path method. I believe it is possible to make it automatic.

+2  A: 

You should overwrite the default_url_options in your application controller.

class ApplicationController > ActionController::Base

  # ...

  def default_url_options(options)
    { :company => current_company.id }
  end

end
Simone Carletti
I get the error wrong number of arguments (0 for 1) for each _path method
Edvinas Bartkus
I can't provide you support unless you post the full exception backtrace and an example of how you implemented it. Also note that current_company.id is just an example I used for the sake of completeness. You should adapt the code to your needs.
Simone Carletti
I have fixed the number of arguments error by changing default_url_options(options) to default_url_options(options={}). However, there is other issue about the arguments. Now I have to specify *_path(:id => @object), because it always expects first argument to be :company object.It is discussed here:https://rails.lighthouseapp.com/projects/8994/tickets/1251-default_url_options-cant-be-used-with-named-routesThanks!
Edvinas Bartkus