On Sun, Aug 9, 2009 at 1:39 AM, Philip Gavrilos <
rails-mailing-l...@andreas-s.net> wrote:

>
> Eric wrote:
> > On Aug 8, 4:08�pm, Philip Gavrilos <rails-mailing-l...@andreas-s.net>
> > wrote:
> >> > � <% end %>
> >>
> >> i did not understand my error here its because im newbie in ruby ( :P )
> >> (if _preview was _post everything was fine.. i think that is because
> >> naming conventions right?)
> >
> > It worked with _post because Rails creates an object for the partial
> > with the same name as the partial filename. Since you were using
> > post.body, etc. in the partial, Rails picked up the post object and
> > displayed everything normally. This broke when you named the partial
> > 'preview' because you were still using post.body, etc. When you use
> > _preview as the partial's filename you also need to change the lines
> > in the partial itself to preview.body, etc. in order for it to work.
> >
> > Furthermore, you can change your instance variable to @previews and
> > do:
> >
> > render :partial => @previews
> >
> > and Rails will look for a posts/_preview.html.erb file, create a
> > 'preview' variable for each element of the @previews object, which can
> > then be used with same preview.body, etc. syntax in the _preview
> > partial as outlined above.
> >
> > TIMTOWTDI, natch, but I think this all is pretty close to what you're
> > asking about.
> >
> > -eric
>
>
>
> thanks Eric.
> your article explain me tha way that partials work. simple and clean :)
>
> but tight now i use the solution that Jaap told me (look above) and
> works fine.
> do you know the difference between them ? is Jaap solution os yours more
> "right" ?
> --
> Posted via http://www.ruby-forum.com/.
>

Hi, another possibility would be to use a custom local variable that was
introduced in Rails 2.2.  For example,

render :partial => "posts/preview", :collection => @posts, :as => :post

Good luck,

-Conrad


>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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