简体   繁体   中英

Rails engine using user profile path from main app

I have a rails engine that needs to link to a user profile. So for example for user joe, I want to do something like link to /profile/show/joe How should the engine access the path to the user profile?

My first instinct was to add a profile_path method to the User model, but this isn't very good because the models don't usually have access to routes and it kind of breaks MVC.

What is the best practice here?

# in your route file
map.connect 'article/:permalink', :controller => 'article', :action => 'view'
# in your views when linking
link_to "View #{article.title}", {:controller => 'designer', :action => 'view', :permalink => article.permalink}
# then in your controller you can use
@article = Article.find_by_permalink(params[:permalink])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM