0
我試圖僅在會話用戶發佈group_message頁面時才顯示group_message_comment的編輯鏈接。僅在會話用戶發表評論時才顯示編輯鏈接
談到group_messages,我設法僅在會話用戶時才顯示編輯鏈接。
<% if @isme %>
<%= link_to 'Edit', edit_group_message_path(@group_message) %>
<% end %>
在另一方面, 談論group_messages_comments,我未能顯示編輯鏈接。我不知道這件事。你可以幫幫我嗎?
☆show.html.erb(group_messages_controller)
<p><b>Post:</b></p>
<div class="each_message">
<%= image_tag @group_message.group.imageurl,:width => '20', :height => '25' %><%= "(" + @group_message.group.name + ")" %>
<p>
<%= 'Page:' + @group_message.page.to_s + '&' %><%= 'Line:' + @group_message.line.to_s %>
<a href="/members/<%= @group_message.member.id%>"><%= @group_message.member.name %></a>
(<%= @group_message.created_at.strftime'%Y-%m-%d %H:%M' %>)
</p>
<div class="group_message">
<p class="message_content"><%= @group_message.content %></p>
</div><!--group_message-->
<br/>
<% if @isme %>
<%= link_to 'Edit', edit_group_message_path(@group_message) %>
<% end %>
</div><!--each_message-->
<hr/>
<b>Comments:</b>
<% if @group_message.group_message_comments.present? %>
<% @group_message.group_message_comments.each do |gmsc|%>
<div class="group_message_comment">
<p><a href="/members/<%= gmsc.member ? gmsc.member.id : "unknown" %>"><%= gmsc.member ? gmsc.member.name : "unknown" %></a> (<%= gmsc.created_at.strftime'%Y-%m-%d %H:%M' %>)</p>
<%= gmsc.content %>
<p>
<% if @isme_comment %>
<%= link_to 'Edit', edit_group_message_comment_path(@group_message.group_message_comments) %>
<% end %>
</p>
</div> <!--group_message_comment-->
<br/>
<% end %><!-- each do -- >
<% else %>
<ul>
<li>no comment yet.</li>
</ul>
<% end %> <!--if -->
☆group_messages_controller
def show
if !checklogin? then return end
@group_message = GroupMessage.find(params[:id])
@isme = me? @group_message
@group_message_comment = GroupMessageComment.new
@group_message_comment = GroupMessage.find(params[:id]).group_message_comments.build
@isme_comment = me? @group_message_comment<!#########--maybe this is wrong-->
respond_to do |format|
format.html # show.html.erb
format.json { render json: @group_message }
end
end
☆application_controller
def me? obj = nil
id_num = obj !=nil ? obj.member_id : params[:id].to_i
if session[:user_id] == id_num then
return true
else
return false
end
end