希望我可以很好地解释这一点,但是如果需要更多的信息,请让我知道!
我正在建立一个用户可以创建“事件”的表单.这个事件有以下关系:
> belongs_to:customer(customer has_many事件)
> belongs_to:user(user has_many事件)
> has_one:incident_status(incident_status属于事件)
该表单允许用户将事件分配给用户(选择表单),然后选择事件状态.事件嵌套在客户端.
但是,我在服务器日志中得到以下内容:
Processing IncidentsController#create (for 127.0.0.1 at 2010-04-26 10:41:33) [POST] Parameters: {"commit"=>"Create","action"=>"create","authenticity_token"=>"YhW++vd/dnLoNV/DSl1DULcaWq/RwP7jvLOVx9jQblA=","customer_id"=>"4","controller"=>"incidents","incident"=>{"title"=>"Some Bad Incident","incident_status_id"=>"1","user_id"=>"2","other_name"=>"SS01-042310-001"}} User Load (0.3ms) SELECT * FROM "users" WHERE ("users"."id" = 2) LIMIT 1 Redirected to http://localhost:3000/session/new Filter chain halted as [:login_required] rendered_or_redirected. Completed in 55ms (DB: 0) | 302 Found [http://localhost/customers/4/incidents]
它看起来像是试图收集有关用户的信息,即使它已经具有id(这是创建事件所需的),用户可能没有权限执行这样的select语句?我很困惑
这是事件控制器中的相关(我认为)信息.
before_filter :login_required,:get_customer def new @incident = @customer.incidents.build @users = @customer.users @statuses = IncidentStatus.find(:all) respond_to do |format| format.html # new.html.erb format.xml { render :xml => @incident } end end def create @incident = @customer.incidents.build(params[:incident]) respond_to do |format| if @incident.save flash[:notice] = 'Incident was successfully created.' format.html { redirect_to(@incident) } format.xml { render :xml => @incident,:status => :created,:location => @incident } else format.html { render :action => "new" } format.xml { render :xml => @incident.errors,:status => :unprocessable_entity } end end end
就像一个FYI,我正在使用restful_authentication插件.
因此,总而言之,当我提交事件创建表单时,它不会因为停止而保存事件.我还是很新的轨道,所以我在诊断这样的问题的技能还是很糟糕的.我要去圈子:)
提前感谢任何帮助.如果需要更多信息,请让我知道,我会在其中进行编辑!
解决方法
只需在控制器中使用以下命令.
before_filter :login_required,:except=>[:new,:create]