开发者

rails sending the wrong content-type in ajax response

开发者 https://www.devze.com 2023-04-06 06:33 出处:网络
I have been struggling terribly for the better part of the day with the following problem: I have a rails 3.1 app - running fine

I have been struggling terribly for the better part of the day with the following problem:

  • I have a rails 3.1 app - running fine
  • I am trying to add some ajax to it

However, no matter what I try, Rails insists on sending the wrong content-type in the response header.

#the form    
= form_for @signup, :url => '/signup', :remote => true do |f|
    = f.text_field :email, :class => 'email', :size => 26
    = f.submit 'Notify me'

#In the controller
def create
  respond_to do |format|
    format.js { render :content_type => 'text/javascript', :layout => false}
  end
end

#the JS file: create.js.erb
alert('HI!');

This is not working, while I think it should. Inspecting the server response with Firebug it tells me the response header has a开发者_JAVA技巧 content-type of text/html. I figure this is why it isn't working (as on a newly generated app, using the same jquery-rails gem it responds with a text/javascript header.

The server says it's responding with JS:

Processing by SignupsController#create as JS

But is somehow refusing to send the correct header. I am lost on where to look next.

Any help or direction as to where to look next would be greatly appreciated! Erwin


Ok found the solution,

So an after_filter in application controller was overriding the content-type. And they are processed inside out. So it was overwriting my declarations.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号