Andrew
Andrew

Reputation: 159

Link_To In Ruby on Rails Is Giving Me Trouble

I'm having trouble with using link_to in Ruby on Rails. I'm making a blog like application which displays a feed of all user posts and allows users to click posts to view/edit them.

This is my _feed partial, which is used to render all the posts of a user.

<% if @feed_items.any? %>
<% @feed_items.in_groups_of(3, false).each do |feeds| %>
<div class="row">
  <% feeds.each do |feed| %>
    <div class="col-md-4">
    <ol class="posts">
    <%= link_to render feed , edit_post_path(feed) %>
      </ol>
    </div>
  <% end %>
</div>
<% end %>
<% end %>

The line <%= link_to render feed , edit_post_path(feed) %> is what is throwing errors. I'm just not 100% certain how to write a link_to which also renders the feed. I've tried a lot of variations and nothing works. The error I get as it is currently written is: undefined method `keys' for "/posts/160/edit":String

This is my Posts controller, which I wrote after this error occurred in an attempt to fix it. I'm not sure if any of this is even necessary:

class PostsController < ApplicationController
before_action :find_note, only: [:show, :edit]

def edit
end

def show
end

private
def find_note
@post = Post.find(params[:id])
end

I'm sure my problem is super basic but I'm having trouble figuring out how to solve it. Any help is appreciated!

Upvotes: 0

Views: 29

Answers (1)

Alex Kojin
Alex Kojin

Reputation: 5204

Use block to render a partial inside of a link:

<%= link_to edit_post_path(feed) do %>
  <%= render feed %>
<% end %>

Upvotes: 1

Related Questions