Ruby on rails 使用t.text:content创建micropost,结果为未经允许的参数“;“文本”;
我已经用microspots创建了一个基本的designe登录,它有:user\u id from:users和t.text:content。如果重要的话,我用scaffold content:text生成了这个。这是micropost控制器:Ruby on rails 使用t.text:content创建micropost,结果为未经允许的参数“;“文本”;,ruby-on-rails,ruby,Ruby On Rails,Ruby,我已经用microspots创建了一个基本的designe登录,它有:user\u id from:users和t.text:content。如果重要的话,我用scaffold content:text生成了这个。这是micropost控制器: class MicropostsController < ApplicationController def new @micropost = Micropost.new end def create @micropo
class MicropostsController < ApplicationController
def new
@micropost = Micropost.new
end
def create
@micropost = Micropost.create(params[:content])
respond_to do |format|
if @micropost.save!
format.html { redirect_to microposts_path, notice: 'Micropost was successfully created.' }
format.json { render :show, status: :created, location: @micropost }
else
format.html { render :new }
format.json { render json: @micropost.errors, status: :unprocessable_entity }
end
end
end
private
def micropost_params
params.require(:micropost).permit( :content)
end
end
class MicropostsController
但是,每次我尝试创建/保存“micropost”时都会导致“unpermitted parameter:text”?感谢您的帮助
_form.html.erb
<%= form_with(model: micropost, local: true) do |form| %>
<% if micropost.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2>
<ul>
<% micropost.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.text_field :text %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
禁止保存此micropost:
表单中的字段是文本
,但字段名称是内容
。将表单中的文本字段更改为:content
这只是我的懒惰,micropost new.html.erb没有form.label或form.text\u are,另外@micropost=micropost.create键入的@micropost.create错误。对不起,伙计们 你的帖子的有效负载是多少?我会假设:content行中的:text列,t.text:content在表中的限制,比如“你好,我的名字是…,再见。”你的意思是-参数:{“utf8”=>“✓", "真实性令牌“=>”TfrayOR1gwsLJEm/X3b/chosonlpdj6svr/re6gn5FIfn5mOi0pgUO5HoiBx0H24+X/cOiJtMq3rqufMy8ZQQ==”,“micropost”=>“{”文本“=>“你好,我的名字是……再见”},“提交”=>“创建micropost”}?或者,@micropost.create(params[:content])?不,我的意思是将您的http post请求的实际正文发送给我。您可以显示表单吗?您已经定义了micropost\u params
,但在create
操作中使用了不太安全的params[:micropost]
。为什么?