filter链暂停为 rendered_or_redirected

希望我能够很好地解释这一点,但如果需要更多信息,请告诉我!

我正在构建一个用户可以创建“事件”的表单。 此事件具有以下关系:

  • belongs_to:客户(客户has_many事件)
  • belongs_to: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插件。

总而言之,当我提交事件创建表单时,它不会保存事件,因为它会停止。 我对rails很新,所以我在诊断这类问题方面的技能仍然非常糟糕。 我要去圈子了。 🙂

在此先感谢您的帮助。 如果需要更多信息,请告诉我,我将对其进行编辑!

只需在控制器中使用以下内容

 before_filter :login_required, :except=>[:new, :create] 

或者您可以跳过此filter:

 skip_before_filter :login_required, only: [:new, :create]