I wrote the code below which doesn't seem to work, but If I delete the last if statement, it does work, obviously for the first two use cases only. Is there a better way to write this code? In my routes file I have
map.resources :galleries
map.resources :users, :has_many => :galleries
A user clicks on the link "galleries" and see a list of all published
galleries.
(mysite.com/galleries
)
A user can click on a link "my galleries" and sees all her own
galleries.
(mysite.com/users/21/galleries
)
A user can clicks on a link on some other user's profile and see that
persons published galleries.
(mysite.com/users/35/galleries
)
if params[:user_id].blank?
@galleries = Gallery.find(:all, :conditions => ['visibility_status= ?', true])
end
if (params[:user_id] && current_user.id.to_s == params[:user_id])
@galleries = current_user.galleries
end
if params[:user_id]
@galleries = Gallery.find(:all, :conditions => ['user_id=? and
visibility_status = ?', params[:user_id], true])
end