ruby on rails - ArgumentError in Posts#edit - first argument nil -


i going through "getting started rails tutorial" , stuck on update aka edit. throwing argumenterror in posts#edit - first argument in form can't nil or empty. here highlighted line:

first argument in form cannot contain nil or empty

extracted source (around line #1):

<%= form_for @post |f| %> 

it seems have started when implemented partial forms part of tutorial.

here post_contoller, edit action , _forms.html respectively:

post_controller:

class postscontroller < applicationcontroller def new @post = post.new end def create   @post = post.new(params[:post].permit(:title, :text))   if @post.save     redirect_to @post   else     render 'new'   end end def show   @post = post.find(params[:id]) end def index   @posts = post.all end def update   @post = post.find(params[:id])   if @post.update(params[:post].permit(:title, :text))     redirect_to @post   else     render 'edit'   end end def destroy   @post = post.find(params[:id])   @post.destroy    redirect_to posts_path end private   def post_params     params.require(:post).permit(:title, :text)   end end 

edit.html

<h1>edit post</h1> <%= render 'form' %> <%= link_to 'back', posts_path %> 

_form.html

 <%= form_for @post |f| %>    <% if @post.errors.any? %>    <div id="error_explanation">      <h2><%= pluralize(@post.errors.count, "error") %> prohibited        post being saved:</h2>      <ul>      <% @post.errors.full_messages.each |msg| %>        <li><%= msg %></li>      <% end %>      </ul>    </div>    <% end %>    <p>      <%= f.label :title %><br>      <%= f.text_field :title %>    </p>     <p>      <%= f.label :text %><br>      <%= f.text_area :text %>    </p>     <p>      <%= f.submit %>    </p>  <% end %> 

the error shows id of "7" record trying update.

all other functions work (show, new, delete) , btw "new" uses same partial form , works fine.

any appreciated. thanks!

u should add in _controller.rb

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

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -