开发者

How do I edit a comment if the ID is not passed via the URL - Rails 3?

So this is my partial:

<% upload_ids = comment.uploads.collect {|u| u.id }%>
<li>
    <div cl开发者_如何学Cass="details">
        <span class="comment_name"><%= (comment.user.username).capitalize %></span> said
        <div class="comment-edit-icons">
            <% link_to(edit_comment_path) do %>
                <span class="icon edit-icon" title="Edit"> </span>
            <% end %>
            <span class="icon destroy-icon" data-destroy-title="Delete <%= comment.id %>?" data-destroy-url="<%= comment_path(comment) %>" title="Delete"> </span>
        </div>
    </div>
    <div class="uploads">
        <% comment.stage.uploads.each do |upload| %>
            <div class="upload-image<% if upload_ids.include?(upload.id) %> selected-image<% end %>" title="<%= upload.name %>"><%= image_tag(upload.image.url(:thumb))%></div>
        <% end %>
    </div>
        <div class="body">
            <%= comment.body %><br />
            <span class="timestamp"><%= time_ago_in_words(comment.updated_at) %> ago</span>
        </div>
</li>

I tried edit_comment_path but that doesn't work because the URL has the ID for another model, not the comments.

The partial that calls this looks like this:

<ul class="comments-list">
<% comments.order("created_at DESC").each do |comment| %>
    <%= render :partial => "comments/show", :locals => {:comment => comment }%>
<% end %>

What I would like to do is have the span with title 'Edit' be the link to editing that particular comment.

How do I do that ?


Unless I am missing something, the following should work as you describe:

edit_comment_path(comment)

The ID comes from the passed ActiveRecord object, in this case a comment, rather than from the current URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜