我有这个功能module MessagesHelper
:
def message_block( message, ticket, comment )
content_tag( :div, :class => "message", :id => "message-" + message.id.to_s ) do
content_tag( :p, message.body, :class => "message-body", :id => "message-body-" + message.id.to_s ) +
content_tag( :div, content_tag( :a, "add comment", :id => "comment-link-" + ticket.id.to_s, :class => "comment-link" ), :id => "comment-" + ticket.id.to_s, :class => "comment" ) +
form_for( comment, :html => { :class => "add-comment", :id => "add-comment-" + ticket.id.to_s } ) do |f|
f.label :body, "add comment"
f.text_area :body
f.submit "add comment"
end
end
end
要获得此预期结果:
<div class="message">
<p></p>
<div class="comment">
</div>
<form class="add-comment">
</form>
</div>
在我的部分观点中,_messages.html.erb
:
<% if !@message.nil? %>
<% @message.each do |m| %>
<%= message_block( m, @ticket, @comment ) %>
<% end %>
甚至没有加载到 DOM中text_area
,我只能看到add comment
按钮。这都在TicketController
(不是MessageController
或CommentController
)中。
对我的问题有任何帮助都会很棒。谢谢你。