How to get 'photo'_url(...) to work?
photo_url(Photo.first, :host => 'foobar') returns http://foobar/photos/2v开发者_Go百科ig0 .
How do I do the same thing with something like 'photo'_url(Photo.first, :host => 'foobar')
Do I need to do something like: 'photo'.constantize._url(Photo.first, :host => 'foobar')
You can use send to invoke a method, once you've concatinated the two parts of the string together.
assuming @fn contains the string "photo":
send("#{@fn}_url", Photo.first, :host => 'foobar')
Or, possibly clearer:
send("photo" + "_url", Photo.first, :host => 'foobar')
How about url_for?
http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for
加载中,请稍侯......
精彩评论