jcollum
jcollum

Reputation: 46579

why would request.format be text/javascript while respond_to format says it's not?

Rails 3.1.1

I'm setting up a dialog that is supposed to post back to the server via ajax, then show a 'done' message when it's completed.

  <%= form_tag '/tracking/add',  :remote => true, :id => 'add_tracking_request', 
      :html => {:'data-type' => 'json'} do %>
  ....

Ok so that's getting back to the server, doing all of its work etc. and then getting to respond_to:

   135          puts 'returning ...'
   136          if current_user
   137            respond_to do |format|
   138              debugger
=> 139              format.html { redirect_to :myTrackingRequests and return }
   140              format.js { head :ok, :success => 'true' }
   141            end
   142          else
   143            raise 'no user found at the end of create tracking'
(rdb:67) e format
#<ActionController::MimeResponds::Collector:0x007f98d63417c0 @default_response=#<Proc:0x007f98d6341720@/Users/user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.1.1/lib/action_controller/metal/mime_responds.rb:268>, @responses={}, @order=[]>
(rdb:67) e format.html
nil
(rdb:67) e format.js
nil
(rdb:67) e format.json
nil
(rdb:67) request.format
text/javascript
(rdb:67) request.post? 
true
(rdb:67) 

I'm in a position where the object passed to respond_to block says it is not html, js or json, but the request is a post and its format is text/javascript. I'm not sure what I'm missing here.

Upvotes: 0

Views: 537

Answers (2)

Jiř&#237; Posp&#237;šil
Jiř&#237; Posp&#237;šil

Reputation: 14402

The format object you get in the respond_to block is just simple container (Collector) that collects responses. It returns nil for every type because the script haven't reached the point where they are actually defined.

See the implementation here ActionController::MimeResponds::Collector.

Upvotes: 0

Valery Kvon
Valery Kvon

Reputation: 4496

<%= form_tag '/tracking/add',  :remote => true, :id => 'add_tracking_request', 'data-type' => 'json' do %>

Upvotes: 1

Related Questions