Jump to content

The ultimate community for Ruby on Rails developers.


Photo

rails 4 respond to produces ActionController::UnknownFormat

rails 4 controllers js javascript

  • Please log in to reply
2 replies to this topic

#1 Vell

Vell

    Dispatcher

  • Members
  • 45 posts
  • LocationWashington, DC

Posted 19 February 2014 - 06:37 AM

Hello all,

 

I am stumped by this issue I am having. I have created a new method in my routes file that I want to have accessible via javascript. Right now, I am getting the following error when I try to access the action:

ActionController::UnknownFormat (ActionController::UnknownFormat

Here is my environment:

 

routes:

  resources :homes do
    collection do
      get 'set_active'
    end
  end

controller

 

  def set_active
    @home = Home.find(params[:id])
    respond_to do |format|
      format.js
    end
  end

index page:

<%= link_to home.status, set_active_homes_path(id: home.id), remote: true %>

If i take out the respond to in the set_active action, it complains of a missing template even though I have a set_active.js file in the views/homes. This leads me to believe the respond_to block is the issue and not the fact that I am sending the JS format from the URL. It looks like this action is only responding to html even though i have put remote: true in the link_to. I am trying to understand what I am missing.

 

I did google around and the only thing I saw was that the js mime-type was not available by default and to add it to the mime-types initializer. But when i did that, rails said that it was already initialized.

 

Am I missing something to be able to add JS/JQuery support?

 

Thanks in advance



#2 danielhanke

danielhanke

    Signalman

  • Members
  • 12 posts
  • LocationCologne, Germany

Posted 02 March 2014 - 06:05 PM

is .js registrered?  or: unregistered for some reason?

 

Mime::EXTENSION_LOOKUP.each { |m| puts m }



#3 Vell

Vell

    Dispatcher

  • Members
  • 45 posts
  • LocationWashington, DC

Posted 03 March 2014 - 12:50 AM

Thanks for the response danielhanke. I actually discovered what the issue was. The errors were being generated by cucumber/capybara. The issue there was that I didn't tell cucumber that I needed to use javascript. Once I put @javascript above my scenario so that cucumber new to use selenium for that test then everything else was able tow work.

 

The way that I had to verify that it was cucumber and not rails was to launch rails server in development and run through the process myself to see if I got the same errors or the typical errors that happen when a javascript is not implemented correctly.

 

It was just weird that instead of cucumber stating that I didn't enable selenium or @javascript for the test that it would just blow up on the action. Im sure cucumber could recognize that this link required javascript just with the remote: true specified. But either way, I learned a valuable lesson from this :) If all else fails try it in rails server and see it for myself :)







Also tagged with one or more of these keywords: rails 4, controllers, js, javascript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users