On 5 August 2010 14:47, bingo bob <[email protected]> wrote:
> like this then? I'm checking for existence of id to deal with the index
> action, i think this might be OTT though?
> ---
>
> def find_baby_name
> �...@baby_name = BabyName.find(params[:id]) if params[:id]
>
> if @baby_name
>
> if @baby_name.user == current_user
> true
> else
> flash[:notice] = "Not authorised."
> redirect_to root_url
> return false
> end
>
> end
>
> end
I was thinking more along the lines of
@baby_names = BabyName.find( :all, :conditions => { user_id =>
current_user.id } )
to get all of them, or
@baby_name = BabyName.find(params[:id], :conditions => { user_id =>
current_user.id }) if params[:id]
if you want to get just one.
In addition if you use a named scope then you don't have to keep
putting the conditions in. Also you might like to look at the
find_by_... methods. Have a look at the rails guide on the Active
Record Query Interface at http://guides.rubyonrails.org/
Colin
Colin
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.