Hi RoR Community,
in Ryan Bates Railscasts Episode #262 he put the index code
<% for message in @messages %>
<div class="message">
<div class="created_at"><%=
message.created_at.strftime("%B %d, %Y")
%></div>
<div class="content">
<%= message.content %>
</div>
<div class="actions">
<%= link_to "Reply", new_message_path(:parent_id =>
message) %> |
<%= link_to "Destroy", message, :confirm => "Are you
sure?",
:method => :delete %>
</div>
</div>
<% end %>
in to a partial _message.html.erb
and call it with
<%= nested_messages @messages.arrange(:order => :created_at) %>
and the following helper method
module MessagesHelper
def nested_messages(messages)
messages.map do |message, sub_messages|
render(message) + content_tag(:div, nested_messages(sub_messages),
:class => "nested_messages")
end.join.html_safe
end
end
I tried the same and it works fine. My Question ist, how do I can force
the helper to render in a different partial like
''_old_message'' or
something else. I tried a lot but everytime the helper render the
_message.html.erb partial.
Thanks ahead for any help!
Regs
Herman
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, in the MessageHelper module, you could change the nested_messages
method to look like this;
def nested_messages(messages)
messages.map do |message, sub_messages|
render(:partial => "old_message", :locals => {:message
=>
message}) + content_tag(:div, nested_messages(sub_messages), :class =>
"nested_messages")
end.join.html_safe
end
Just change the partial option to what ever file you want to render.
On Nov 1, 1:54 pm, Herman Müller
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi RoR Community,
>
> in Ryan Bates Railscasts Episode #262 he put the index code
>
> <% for message in @messages %>
> <div class="message">
> <div class="created_at"><%=
message.created_at.strftime("%B %d, %Y")
> %></div>
> <div class="content">
> <%= message.content %>
> </div>
> <div class="actions">
> <%= link_to "Reply", new_message_path(:parent_id =>
message) %> |
> <%= link_to "Destroy", message, :confirm => "Are
you sure?",
> :method => :delete %>
> </div>
> </div>
> <% end %>
>
> in to a partial _message.html.erb
>
> and call it with
>
> <%= nested_messages @messages.arrange(:order => :created_at) %>
>
> and the following helper method
>
> module MessagesHelper
> def nested_messages(messages)
> messages.map do |message, sub_messages|
> render(message) + content_tag(:div, nested_messages(sub_messages),
> :class => "nested_messages")
> end.join.html_safe
> end
> end
>
> I tried the same and it works fine. My Question ist, how do I can force
> the helper to render in a different partial like
''_old_message'' or
> something else. I tried a lot but everytime the helper render the
> _message.html.erb partial.
>
> Thanks ahead for any help!
>
> Regs
>
> Herman
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Justin, works fine!! Thanks a lot! Regs Herman Justin Mcginnis wrote in post #1029688:> Hi, in the MessageHelper module, you could change the nested_messages > method to look like this; > > def nested_messages(messages) > messages.map do |message, sub_messages| > render(:partial => "old_message", :locals => {:message => > message}) + content_tag(:div, nested_messages(sub_messages), :class => > "nested_messages") > end.join.html_safe > end > > Just change the partial option to what ever file you want to render.-- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.