Hello I'm getting the error below by using Rails 4. My front-end(EmberJs) provides json.
Started POST "/articles" for 127.0.0.1 at 2014-03-30 00:54:18 -0400 Processing by ArticlesController#create as JSON Parameters: {"article"=>{"title"=>"Title", "body"=>"Content", "author_id"=>"2", "author"=>nil}} Unpermitted parameters: author Completed 500 in 4782ms
NoMethodError (undefined method []' for nil:NilClass):
app/controllers/articles_controller.rb:43:inblock in create'
app/controllers/articles_controller.rb:42:in `create'
My Model looks like this:
class Article < ActiveRecord::Base
validates :title, presence: true
validates :body, presence: true
attr_accessible :title, :body, :author_id
belongs_to :author
end
My controller looks like this:
class ArticlesController < ApplicationController
def new
@article = Article.new
respond_to do |format|
format.json { render json: @article }
end
end
def create
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.json { render json: @article, status: :created, location: @article }
else
format.json { render json: @article, status: :unprocessable_entity }
end
end
end
private
def article_params
params.require(:article).permit(:title, :body, :author_id)
end
end