Wesly Wesly - 7 months ago 8
Ruby Question

Trying to to add a nested post with the ancestry gem

I have topics and posts and they both have relationships. I've been following the guide on how to add a nested post but when i try to reply to a post i get

Couldn't find Topic with 'id'=
.

In my
Posts
controller

def create
@topic = Topic.find params[:topic_id]
@post = Post.new(post_params)
@post.user_id = current_user.id
@post.topic_id = @topic.id
if @post.save
redirect_to @topic
else
render :new
end
end


In my
Topics
controller

def show
@topic = Topic.find params[:id]
@post = Post.new(:parent_id => params[:parent_id])
@posts = @topic.posts
@topic.punch(request)
end


I'll keep it short for how i have my reply button in my topics/show.html.erb page

<% @posts.each do |post| %>
<%= link_to "Reply", new_topic_post_path(@topic, :parent_id => post) %>
<% end %>


Now this is my form

<%= simple_form_for [@topic, @post] do |f| %>
<%= f.hidden_field :parent_id %>
<%= f.input :content, as: :pagedown, input_html: { preview: true, rows: 10 }, label: 'Markdown' %>
<%= f.submit "Post", class: 'button expanded' %>
<% end %>

Answer

@Kristj√°n Answered my question. I was missing params[:topic_id]

Comments