Jump to content

The ultimate community for Ruby on Rails developers.


Photo

uninitialized constant ApplicationController::Base


  • Please log in to reply
2 replies to this topic

#1 YamilBracho

YamilBracho

    Passenger

  • Members
  • 2 posts

Posted 11 September 2013 - 09:25 PM

Hi

I am trying to return json from my controller. My code is :

class DiscosController < ApplicationController::Base
   respond_to :json
   
   def index
      @discos = Disco.all
	  respond_with(@discos)
    end
   
end

And when I run my app, i got :

 

Routing Error

 

uninitialized constant ApplicationController::Base

 

Try running rake routes for more information on available routes.

 

My routes.rb is:

 

DemoApp::Application.routes.draw do
  resources :discos
  root to: "discos#index"
end
 
 
Any hint ?
TIA
 


#2 YamilBracho

YamilBracho

    Passenger

  • Members
  • 2 posts

Posted 11 September 2013 - 09:35 PM

I changed:

#respond_with(@discos)

to

render json: @discos

 

And it works!!!. It shows the json on the browser, so what it's the difference between respond_with and render ? I going to get that response with Backbone...



#3 katafrakt

katafrakt

    Signalman

  • Members
  • 16 posts
  • LocationKrak√≥w, PL

Posted 12 September 2013 - 05:56 AM

I'm not sure why it works. It should be DiscosController < ActionController::Base or DiscosController < ApplicationController in standard Rails scaffold (3.1 at least).






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users