使用 mongrel_rails start 无法获取值 params[:user] 第一个请求?
当我使用 mongrel_rails start 启动我的 mongrel 服务器时,我在控制器的第一个请求的创建操作中从 params[:user] 得到 nil 。 之后第二次、第三次就OK了。 另外,如果我使用脚本/服务器启动我的 Mongrel,它根本没有任何问题。 script/server 和 mongrel_rails start 之间启动 mongrel server 有什么不同吗? 你有遇到过这个问题吗?
这是我在控制器中的代码:
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
flash[:notice] = 'User was successfully created.'
format.html { redirect_to(@user) }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
我使用 Poster 插件来测试并以 xml 格式发布。
I get nil from params[:user] in create action of my controller for the first request when I start my mongrel server by using mongrel_rails start. After that for second and third time are ok. In addition, if I start my Mongrel by using script/server, it doesn't have any problems at all. It is different by starting mongrel server between script/server and mongrel_rails start? Have you ever faced this problem?
Here my code in controller:
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
flash[:notice] = 'User was successfully created.'
format.html { redirect_to(@user) }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
And I use Poster add-on to test and post in xml format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要检查的第一件事是控制器中的新操作。
第二个是包含您的表单的 erb 文件。 我感觉文本字段标签不正确。
我建议通过以下方式检查 params 对象:
First thing you want to check is the new action in your controller.
Second is the erb file which has your form. I have a feeling the text field tags are not proper.
I'd recommend inspecting the
params
object by: