Hi
I'm building a job board that uses a User model and a Job model. A user has
many jobs, and a job belongs to a user.
I need the board to act like this:
If a user is logged in, he can see the jobs he created at
/users/:user_id/jobs. If a user is not logged in, he can see all the jobs
created by all users at /jobs.
Currently I have 2 routes who route to the same index action.
*config/routes.rb*
*
*
resources :users do
resources :jobs, shallow: true
end
resources :jobs, only: [:index]
*rake routes*
*
*
user_jobs GET /users/:user_id/jobs(.:format) jobs#index
jobs GET /jobs(.:format) jobs#index
Do I need the index action to conditionally check for the params[:user_id]
or is there a better way to accomplish this?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/3610385b-f8fa-4709-acb9-a433add7e1e9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.