Rubyx Rubyx - 23 days ago 5
Ruby Question

undefined method `model_name' with simple_form on Rails 5

I'm getting an

undefined method 'model_name'
error with simple_form when I want to edit a basic post on Rails 5.

show.html.haml:

= link_to "Edit", edit_post_path(@post)


edit.html.haml:

= simple_form_for @post do |f|
= f.input :title
= f.input :link
= f.input :description

= f.button :submit


posts_controller.rb:

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

def edit
end

def update
if @post.update(post_params)
redirect_to @post
else
render 'edit'
end
end


Any idea?

Answer
def edit
  @post = Post.find(params[:id]) # <=========
end