Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4-ActiveModel::禁止属性错误_Ruby On Rails_Ruby On Rails 4_Strong Parameters - Fatal编程技术网

Ruby on rails Rails 4-ActiveModel::禁止属性错误

Ruby on rails Rails 4-ActiveModel::禁止属性错误,ruby-on-rails,ruby-on-rails-4,strong-parameters,Ruby On Rails,Ruby On Rails 4,Strong Parameters,我读过其他关于它的文章,但仍然不能指出是什么导致了这个错误。我已经定义了Rails 4的强参数,但它一直显示错误: ActiveModel::禁止MessagesController#create中的属性错误 我的看法是: <%= form_for(@message) do |f| %> <div class="form-group field"> <%= f.label :phrase %> <br/> <%= f.te

我读过其他关于它的文章,但仍然不能指出是什么导致了这个错误。我已经定义了Rails 4的强参数,但它一直显示错误:

ActiveModel::禁止MessagesController#create中的属性错误

我的看法是:

<%= form_for(@message) do |f| %>
    <div class="form-group field">
  <%= f.label :phrase %>
  <br/>
  <%= f.text_field :phrase,  autofocus: true, class: 'form-control' %>
</div>
<div class="form-group field">
  <%= f.label :date %>
  <br/>
  <%= f.date_field :date, class: 'form-control' %>
</div>
<div class="actions text-center">
  <%= f.submit "Submit", class: 'btn btn-default' %>
</div>
<% end %>



我的控制器:

class MessagesController < ApplicationController

def today
    @dates = Message.all()
end

def history
    @messages = Message.history_checker
end

def new
    @message = Message.new
end

def create
    @message = Message.new(params[:message])
    if @message.save
        flash[:notice] = "OK"
        redirect_to root_path
    else
        render :action => 'new'
    end
end

private

def message_params
  params.require(:message).permit(:phrase,:date)
end 
end
class messages控制器“新建”
结束
结束
私有的
def消息参数
参数require(:message).permit(:短语,:日期)
结束
结束

错误指向控制器
@message=message.new(参数[:message])
的第15行。有什么想法吗?

你只需要使用
message\u params
而不是
params[:message]

@message = Message.new(message_params)

您只需要使用
message_params
而不是
params[:message]

@message = Message.new(message_params)

现在可以用了,谢谢!,但是,我可以问一下message_params和params[:message]之间到底有什么区别吗?我有点困惑,因为我在另一个项目中使用了params[:object],它运行起来没有问题。这个项目和另一个项目的Rails版本是什么?@Vicvans阅读强参数@oscar都在Rails 4.1上,现在可以运行了,谢谢!,但是,我可以问一下message_params和params[:message]之间到底有什么区别吗?我有点困惑,因为我在另一个项目中使用了params[:object],它运行起来没有问题。这个和另一个projet的Rails版本是什么?@Vicvans阅读了强参数@oscar都在Rails 4.1上