希望我可以很好地解釋這一點,但請讓我知道是否需要更多信息!過濾器鏈暫停爲[:login_required] rendered_or_redirected
我正在建立一個表單,用戶可以創建一個「事件」。這起事件有如下關係:
- belongs_to的:客戶(客戶的has_many事件)
- belongs_to的:用戶(用戶的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(這是所有需要創建事件),並且用戶可能沒有權限執行類似的選擇語句?我很困惑。
以下是事件控制器中的相關信息(我認爲)。
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插件。
所以總而言之,當我提交事件創建表單時,它不會保存事件,因爲它會暫停。我對鐵軌還是很陌生,所以我診斷這類問題的技巧仍然很糟糕。我正在圈圈。 :)
在此先感謝您的幫助。請讓我知道是否需要更多信息,我會編輯它!
謝謝。這就是訣竅! – Magicked 2010-04-26 15:21:51