Question

In my index.html, i use <%= render 'rates/rate_form'%> to render the rate form, and the form is ajax.The content of _rate_form is:

   `<%= form_for [@image, Rate.new], :remote=>true do |f| %>  
<input type="hidden" name="image_id" value="<%= @image.id%>"/>
<button type="submit"> Rate</button>
<% end %>`

In my Rates controller, i defined one before_filter, only signed in use can create rate. class 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

in my sesson_helper file:

 def authenticate
   redirect_to signin_url unless signed_in? 
 end

The log is:

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)

When i click the Rate button, there is error in console: Filter chain halted as :deny_access rendered or redirected Do you have any idea how to solve it? Thanks a lot!

Was it helpful?

Solution

So you have a filter that runs before every execution of the create action. What it does is that it redirects unconditionally. This effectively means that nobody will ever be able to call the create action. I suppose there should be some check within deny_access that verifies a logged in session, or so.

The Message you see in the logs just informs you that the filter did redirect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top