Filter chain halted as [:login_required] rendered_or_redirected

我是研究僧i 提交于 2019-12-04 18:11:34

问题


Hopefully I can explain this well enough, but please let me know if more information is needed!

I'm building a form where a user can create an "incident". This incident has the following relationships:

  • belongs_to: customer (customer has_many incidents)
  • belongs_to: user (user has_many incidents)
  • has_one: incident_status (incident_status belongs to incident)

The form allows the user to assign the incident to a user (select form) and then select an incident status. The incident is nested in customer.

However, I'm getting the following in the server logs:

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]

It looks to me like it's trying to gather information about the user, even though it already has the id (which is all it needs to create the incident), and the user may not have permission to do a select statement like that? I'm rather confused.

Here is the relevant (I think) information in the Incident controller.

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

Just as an FYI, I am using the restful_authentication plugin.

So in summary, when I submit the incident creation form, it does not save the incident because it halts. I'm still very new to rails, so my skill at diagnosing problems like this is still very bad. I'm going in circles. :)

Thanks in advance for any help. Please let me know if more information is needed and I'll edit it in!


回答1:


Just use following in your controller.

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



回答2:


Or you can skip this filter:

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


来源:https://stackoverflow.com/questions/2714537/filter-chain-halted-as-login-required-rendered-or-redirected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!