I wonder is there possibility to get path from array outside views (in my case in model) like in link_to method - link_to 'User', [:admin, @user] .
For example I want to store admin_artist_path (unfortunately real problem is more complex because I can't predict what path will be )
class MenuItem < ActiveRecord::Base
include Rails.application.routes.url_helpers
before_save :store_path!
private
def store_path!
self.url = [:namespace, :artist].do_some_magick
end
end
ps. I know about url_for() method but for some reasons it must be path.
Thanks for help!
I believe you need to include both of these classes
include ActionDispatch::Routing::PolymorphicRoutes
include Rails.application.routes.url_helpers
before_save :store_path!
private
def store_path!
self.url = polymorphic_path([:namespace, :artist])
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With