Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter chain halted as [:login_required] rendered_or_redirected

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!

like image 366
Magicked Avatar asked Apr 26 '10 15:04

Magicked


2 Answers

Just use following in your controller.

before_filter :login_required, :except=>[:new, :create]
like image 191
Salil Avatar answered Oct 13 '22 07:10

Salil


Or you can skip this filter:

skip_before_filter :login_required, only: [:new, :create]
like image 30
freemanoid Avatar answered Oct 13 '22 07:10

freemanoid