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?
当我使用mongrel_rails start启动我的mongrel服务器时,我在第一个请求的创建操作中从params [:user]获得nil。之后第二次和第三次都可以。另外,如果我使用脚本/服务器启动我的Mongrel,它根本没有任何问题。通过在脚本/服务器和mongrel_rails启动之间启动mongrel服务器是不同的?你有没遇到过这个问题?
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.
我使用Poster附加组件以xml格式进行测试和发布。
1 个解决方案
#1
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.
您要检查的第一件事是控制器中的新操作。第二个是具有您的表单的erb文件。我感觉文本字段标签不合适。
I'd recommend inspecting the params
object by:
我建议通过以下方式检查params对象:
logger.debug params.inspect # Will show up log/development.log
puts params.inspect # Will show up in server console
#1
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.
您要检查的第一件事是控制器中的新操作。第二个是具有您的表单的erb文件。我感觉文本字段标签不合适。
I'd recommend inspecting the params
object by:
我建议通过以下方式检查params对象:
logger.debug params.inspect # Will show up log/development.log
puts params.inspect # Will show up in server console