ruby on rails cannot use permit.require -


i'm trying build simple blog on rails 5. have created post model:

create_table "posts", force: :cascade |t|   t.string "title"   t.text "body"   t.integer "category_id"   t.integer "author_id"   t.datetime "created_at", null: false   t.datetime "updated_at", null: false end 

and controller methods:

def new     @post = post.new     @categories = category.all  end  def create     @post = post.new(post_params)     if @post_save         redirect_to posts_path, :notice => "post has benn created"     else         render "new"     end  end  def post_params     params.require(:post).permit(:title, :body, :category_id) end  

when try add post via html form nothing happens. page form reloaded , post not saved. doing wrong?

that's because there's typo in create method

@post_save must @post.save

def create   @post = post.new(post_params)   if @post.save     redirect_to posts_path, :notice => "post has been created"   else     render "new"   end end 

since @post_save not defined, else block evaluated , new page rendered , nothing happens


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -