开发者

Use a string with forward slashes as a single parameter in routes.rb

Sorry about that confusing title :) I have a resource, ComatosePage (used in the comatose cms plugin), which has a table called 开发者_运维百科comatose_pages which has a field 'full_path' which has values like this: "en/home/logged-in/subscriber/school-top" to set up a route so that i can use this full_path field to load a ComatosePage from the db, instead of the standard id field, so that this url:

/comatose_admin/en/home/logged-in/subscriber/school-top

loads the comatose_admin controller's edit action, passing everything after comatose_admin/ through as a parameter, ie generates this for rails:

Parameters: {:controller => "comatose_admin", :action => "edit", :full_path => "en/home/logged-in/subscriber/school-top"}

The complication lies in the fact that the string is broken up with forward slashes, which is going to confuse routes, i think. Can i set up routes to take everything after "comatose_admin/" and put it into a single parameter?


You can use wildcards in your routes that will match forward slashes. Try something like this:

"/comatose_admin/*full_path"

Then params[:full_path] should contain the rest of the request path.

See Route Globbing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜