在我的 index.html 中,我使用 <%= render 'rates/rate_form'%> 来渲染费率表单,表单是ajax。_rate_form的内容是:
`<%= form_for [@image, Rate.new], :remote=>true do |f| %>
<input type="hidden" name="image_id" value="<%= @image.id%>"/>
<button type="submit"> Rate</button>
<% end %>`
在我的 Rates 控制器中,我定义了一个 before_filter,只有登录使用才能创建速率。类 RatesController < ApplicationController before_filter :authenticate, :only=> :create
def create
@rate=Rate.new(:rate=>1)
respond_to do |format|
if @rate.save
format.html { redirect_to(@rate) }
format.js
end
end
end
在我的 sesson_helper 文件中:
def authenticate
redirect_to signin_url unless signed_in?
end
日志是:
Redirected to http://localhost:3000/signin
Filter chain halted as :authenticate rendered or redirected
Completed 302 Found in 3ms (ActiveRecord: 0.7ms)
Started GET "/signin" for 127.0.0.1 at 2013-04-28 12:36:56 +0300
Processing by SessionsController#new as JS
Rendered sessions/new.html.erb within layouts/application (1.3ms)
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Rendered sessions/new.html.erb (1.2ms)
Rendered layouts/_nav.html.erb (4.8ms)
Rendered layouts/_search.html.erb (0.6ms)
Rendered layouts/_notice_div.html.erb (0.1ms)
Completed 200 OK in 26ms (Views: 24.3ms | ActiveRecord: 0.9ms)
当我单击“速率”按钮时,控制台出现错误:过滤器链因 :deny_access 渲染或重定向而停止 你知道如何解决吗?非常感谢!