在活动管理控制器操作上跳过身份验证

时间:2014-09-09 15:03:05

标签: ruby-on-rails authentication devise activeadmin

我试图允许Arduino通过URL中的params定期将数据发布到我的Rails应用程序。我希望处理此操作的控制器操作跳过身份验证,这样我就不必担心Arduino上的auth。我的控制器在这里:

controller do
    skip_before_filter :authenticate_admin_user!
    def capture_data
        new_record = BoxHouseDataLog.new
        new_record.box_number = params[:box_number]
        new_record.run_time_hours = params[:run_time_hours]
        new_record.run_time_minutes = params[:run_time_minutes]
        new_record.run_time_seconds = params[:run_time_seconds]
        new_record.air_temp = params[:air_temp]
        new_record.loop_temp = params[:loop_temp]
        new_record.rh = params[:rh]
        new_record.co2 = params[:co2]
        new_record.o2 = params[:o2]
        new_record.air_temp_setpoint = params[:air_temp_setpoint]
        new_record.loop_temp_setpoint = [:loop_temp_setpoint]
        new_record.rh_setpoint = params[:rh_setpoint]
        new_record.co2_setpoint = params[:co2_setpoint]
        new_record.save
    end
end

在我的/config/initializers/active_admin.rb文件中:

config.authentication_method = :authenticate_admin_user!
config.skip_before_filter :authenticate_admin_user!

当我尝试发出请求时,我收到401 Unauthorized Error并被重定向以创建与Devise的新会话。

更新: 这是日志...

  

开始GET   " / capture_data box_number = 1&安培; run_time_hours = 111&安培; run_time_minutes = 11&安培; run_time_seconds = 11&安培; air_temp = 111.11&安培; loop_temp = 111.11&安培; RH = 111.11&安培; CO 2 = 111.11&安培; O2 = 111.11&安培; air_temp_setpoint = 111.11&安培; loop_temp_setpoint = 111.11&安培; rh_setpoint = 111.11&安培; co2_setpoint = 111.11&安培;方法=交"   for 127.0.0.1 at 2014-09-10 11:21:44 -0400处理方式   Admin :: BoxHouseDataLogsController#capture_data as HTML参数:   {" box_number" =>" 1"," run_time_hours" =>" 111"," run_time_minutes" = >" 11&#34 ;,   " run_time_seconds" =>" 11"," air_temp" =>" 111.11"," loop_temp" = >" 111.11&#34 ;,   " rh" =>" 111.11"," co2" =>" 111.11"," o2" =>" 111.11&#34 ;,   " air_temp_setpoint" =>" 111.11"," loop_temp_setpoint" =>" 111.11",   " rh_setpoint" =>" 111.11"," co2_setpoint" =>" 111.11","方法" =>"后"}   在4.0ms完成401 Unauthorized

     

开始GET" / admin / login"对于2014.0-10 11:21:44 -0400的127.0.0.1   由ActiveAdmin :: Devise :: SessionsController处理#new为HTML   弃权警告:f.buttons不赞成使用f.actions。   (从按钮处调用   C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/form_builder.rb:119)   弃用警告:不推荐使用f.commit_button   f.action(:提交)。 (从commit_button调用   C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/form_builder.rb:99)   在其中呈现active_admin / devise / sessions / new.html.erb   layouts / active_admin_logged_out(77.3ms)在302.5ms内完成200 OK   (浏览次数:120.3ms | ActiveRecord:0.0ms)

0 个答案:

没有答案