希望我能很好地解释这一点,但如果需要更多信息,请告诉我!
我正在构建一个表单,用户可以在其中创建“事件”。此次事件有如下关系:
- 属于:客户(客户有很多事件)
- belongs_to:用户(用户有很多事件)
- 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
仅供参考,我正在使用restful_authentication 插件。
总之,当我提交事件创建表单时,它不会保存事件,因为它停止了。我对 Rails 还很陌生,所以我诊断此类问题的能力仍然很差。我要绕圈子了。 :)
预先感谢您的任何帮助。如果需要更多信息,请告诉我,我将对其进行编辑!