过滤器链因 [:login_required] 渲染_或重定向而停止 [英] Filter chain halted as [:login_required] rendered_or_redirected

查看:38
本文介绍了过滤器链因 [:login_required] 渲染_或重定向而停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:客户(客户有_许多事件)
  • belongs_to:用户(用户有_许多事件)
  • has_one:incident_status(incident_status属于事件)

该表单允许用户将事件分配给用户(选择表单),然后选择事件状态.事件嵌套在客户中.

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]

在我看来,它正在尝试收集有关用户的信息,即使它已经拥有 id(这是创建事件所需的全部内容),并且用户可能无权执行这样的选择语句?我有点糊涂了.

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

仅供参考,我正在使用 restful_authentication 插件.

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

所以总而言之,当我提交事件创建表单时,它没有保存事件,因为它停止了.我对 Rails 还是很陌生,所以我诊断此类问题的技能仍然很差.我在兜圈子.:)

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!

推荐答案

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

Just use following in your controller.

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

这篇关于过滤器链因 [:login_required] 渲染_或重定向而停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆