On Mar 2, 8:39 am, phil7085 <[email protected]> wrote:
> Ok I've got it to work by using this in my partial:
>
> <%= @advert[:title] %>
>
> Can you tell me why I have to reference like this?
>
The errors you mentionned imply that @advert isn't actually an
instance of the Advert class.

Fred
> Phil
>
> On Mar 2, 8:22 am, phil7085 <[email protected]> wrote:
>
> > Hi guys,
>
> > I've tried both of those options and can't get it to work, I think
> > it's the way I am trying to retrieve the values in the partial.
>
> > In the development.log I have this error: undefined method `title' for
> > #<HashWithIndifferentAccess:0x1f7f930>
>
> > In my controller I have this:
>
> > render :partial => 'advert', :object => @advert
>
> > And in my partial I have tried both if these:
>
> > <%= advert.title %>
> > <%= @advert.title %>
>
> > No luck.
>
> > Any suggestions?
>
> > Phil
>
> > On Mar 1, 8:59 pm, phil7085 <[email protected]> wrote:
>
> > > Thanks,
>
> > > I will give this a try, although as a newbie this talk
> > > of :locals, :object, etc has slightly gone over my head. I'm sure i'll
> > > get it.
>
> > > Phil
>
> > > On Mar 1, 8:37 pm, Phlip <[email protected]> wrote:
>
> > > > phil7085 wrote:
> > > > > How would I then need to tell rails to use the @advert object because
> > > > > that's the part that I have been having trouble with?
>
> > > > Formerly, it was this:
>
> > > >   def preview
> > > >     @advert = Advert.new(params[:advert])
> > > >     render :partial => 'advert', :locals =>{ :@advert => @advert }
> > > >   end
>
> > > > I prefer that style because it makes @advert, inside the partial, safe 
> > > > to test
> > > > for nil. However, on our latest new project (Rails 2.2.2) either we did
> > > > something else wrong, or the :@ stopped working, and we had to use this:
>
> > > >     render :partial => 'advert', :locals =>{ :advert => @advert }
>
> > > > Does anyone know if the :@ trick should still work?
>
> > > > --
> > > >    Phlip
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to