Cogman
Cogman

Reputation: 2150

How can I include unix path information in a rails link_to

I have an application which needs to handle path information (it will be working with files on the server). Here is how I'm trying to do the route.

match "viewfile/file=:vFile" => "home#viewfile"

and here is how I'm trying to link to the file

link_to("file",
       { :controller => "home", :action => "viewfile", :vFile => "/this/is/a/test" })

This, however, throws errors and does not work.

How can I do this?

Upvotes: 0

Views: 62

Answers (2)

Travis
Travis

Reputation: 10547

link_to("file", { ... url_encode("/this/is/a/test/") })

Is more likely to work.

Upvotes: 1

sled
sled

Reputation: 14635

the problem is the routing does not know which route to match because multiple routes could match your controller/action/vFile combination, so name the route like:

match "viewfile/file=:vFile" => "home#viewfile", :as => 'viewfile'

now you can use the viewfile_path helper

link_to 'file', viewfile_path("/this/is/a/test")

PS: I don't know if it works with the equal (=) sign in the url, what definitely works is:

match "viewfile/file/:vfile" => "home#viewfile", :as => 'viewfile'
link_to 'file', viewfile_path("/this/is/a/test")

but give it a try...

Upvotes: 0

Related Questions