On Wed, Jan 21, 2009 at 10:12 AM, Mohammad Abed <
rails-mailing-l...@andreas-s.net> wrote:

>
> 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
> --
>
What part doesn't seem to work?

Could it be fixed if you structured the code as:

if params[:user_id].blank?
  blah_blah_blah
else
  if current_user.id.to_s == params[:user_id]
    blah_blah
  else
    blah
  end
end

--wpd

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to