ruby - Rails link_to existing route -


i'm trying link action in controller view. when rake routes, see

document_version_file_index    /document_versions/:document_version_id/file(.:format)           file#index 

i think that's route want hit. controller called document_versions_controller , includes action called download want call. when try

<%= link_to linktext, :document_version_file  %> 

i routing error:

no route matches {:action=>"show", :controller=>"files"} 

there no files controller. i'm trying hit document_version controller. doing wrong?

edit: how building route:

resources :document_versions     resources :files     member        'download', :action => :download       resources :document_version     end   end  

edit 2: can step , pretend don't have route in existence already? have view , controller. controller has def download, named document_versions_controller.rb , has class documentversionscontroller < applicationcontroller. how can make route hits download method , call link click in view?

that route requires :document_version_id argument, can't call straight-up that. way use route be:

document_version_file_index_path(@document_version_file) 

i'm not sure why route has index in name, automatically generated routes don't.

the easy way remember how routes work every :x type argument in path that's not optional, not inside brackets, provide value in call in order appear.

a route /:a/:b.(:c) can called x(a,b) or x(a,b,c), either way valid, :c optional.


Comments

Post a Comment

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -