photo_url(Photo.first, :host => 'foobar')返回http://foobar/photos/2vig0。
我如何用'photo'_url(Photo.first, :host => 'foobar')这样的东西做同样的事情?
我需要做像这样的事情吗:'photo'.constantize._url(Photo.first, :host => 'foobar')
发布于 2011-08-10 13:34:38
一旦将字符串的两个部分连接在一起,就可以使用send调用方法。
假设@fn包含字符串"photo"
send("#{@fn}_url", Photo.first, :host => 'foobar')或者,可能更清楚:
send("photo" + "_url", Photo.first, :host => 'foobar')发布于 2011-08-10 13:41:20
那url_for呢?
http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for
https://stackoverflow.com/questions/7006319
复制相似问题