Well, I started to study the rails and, of course, I started writing a service with personal blogs (something like livejournal). I have scaffold posts and a custom model (thanks Devise). Now I'm trying to show all the messages of a specific user with something like / username / posts in the url, but I really can not figure out how to do this. Nested resources already created in routes
resources :users do resources :posts end
and connected user and mail models using
has_many :posts
and
belongs_to :user
Should I create a controller for the user or not? Is there any suitable way for this?
PS Thanks for the answer. Trying to learn the rails, but almost every tutorial I found ends with scaffolding and that is not very useful.
Edit 1: Thanks to the idea of ββa βmatch,β I solved half the problem. The other (unauthorized) half selects messages written by a specific user
Edit 2: Added
@user = User.where(:username => params[:username]) @posts = @user.posts
For the controller, but I have a "undefined method` posts' "error in the message controller.
source share