Javascript #一个简单的RubyonRails和Angularjs项目出现500个错误

Javascript #一个简单的RubyonRails和Angularjs项目出现500个错误,javascript,ruby-on-rails,ruby,angularjs,general-network-error,Javascript,Ruby On Rails,Ruby,Angularjs,General Network Error,谢谢你花时间帮我解决这个问题。我是Ruby新手,所以这似乎是一个简单的答案。我创建了一个api,允许Ruby和Angularjs相互通信。空气污染指数如下: class EntriesController < ApplicationController respond_to :json protect_from_forgery def index respond_with Entry.all end def show respond_with Entry.find(pa

谢谢你花时间帮我解决这个问题。我是Ruby新手,所以这似乎是一个简单的答案。我创建了一个api,允许Ruby和Angularjs相互通信。空气污染指数如下:

class EntriesController < ApplicationController
respond_to :json
protect_from_forgery

def index
    respond_with Entry.all
end

def show
    respond_with Entry.find(params[:id])
end

def create
    respond_with Entry.create(params[:entry])
end

def update
    respond_with Entry.update(params[:id], params[entry])
end

def destroy
    respond_with Entry.destroy(params[:id])
end
end
$scope.entries=Entry.query()工作完全正常,但创建条目根本不工作。我得到一个错误:

POST http://localhost:3000/entries 500 (Internal Server Error)

ActiveModel::ForbiddenAttributesError in EntriesController#create
ActiveModel::ForbiddenAttributesError

Extracted source (around line #14):
12
13 def create
14 respond_with Entry.create(params[:entry])
15 end

我不知道为什么会出现这个错误。我很感激能得到的任何帮助。谢谢大家!

您的控制器显示您不允许/说明

在控制器中,需要一个方法来指示模型允许使用哪些参数

def create
  @entry = Entry.new(entry_params)
  @entry.save
  respond_with(@entry)
end 

private 
def entry_params
  params.require(:entry).permit(:attribute, :another_attribute)
end

您将收到一个
禁止属性错误

您需要明确指定哪些参数被列入批量更新的白名单:

这是一个类似问题的解决方案:

def create
  @entry = Entry.new(entry_params)
  @entry.save
  respond_with(@entry)
end 

private 
def entry_params
  params.require(:entry).permit(:attribute, :another_attribute)
end