I have resource bio and in views and link for add new bio is:
= link_to "Add new bio", [:new, :admin, :bio]
If I put resource :bio to scope like this:
namespace :admin do
scope "/:bio_type", :defaults => {:bio_type => "company"} do
resources :bios
end
end
This doesn’t work
= link_to "Add new bio", [:new, :admin, :bio, { bio_type: params[:bio_type] }]
My question is how can I add scoped param to url_for helper? And can rails do this by default?
p.s. new_admin_bio_path({bio_type: params[:bio_type]}) works fine, but it’s just curious
I believe you cannot make this with array params to
link_to. You have to usepolymorphic_pathornew_admin_bio_path({bio_type: params[:bio_type]})The reason is that
link_tocallsurl_forwith[:new, :admin, :bio, { bio_type: params[:bio_type] }], which callspolymorphic_pathwith these params.Check the source code for url_for and for polymorphic_url.
Notice, that
polymorphic_urltakes 2 params –record_or_hash_or_arrayandoptions, buturl_forcalls it with one parameter only.So, correct call with the
scopeoption should sound like