Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError in PinsController#index: declare the formats your controller responds to in the class level

While working on my rails app I created a "Pins" scaffold using the following command in my terminal:

rails generate scaffold Pins description:string --skip-stylesheets

This creates the scaffold in my applications and then I run:

rake db:migrate

and it goes through without a hitch. I didn't alter any of the generated pages but when I finally try to access the new scaffold on localhost:3000 is gives me the following error:

RuntimeError in PinsController#index

In order to use respond_with, first you need to declare the formats your controller responds to in the class level Rails.root: /Users/code/appname

Application Trace | Framework Trace | Full Trace

app/controllers/pins_controller.rb:6:in `index'

I've been following a video tutorial to create my app and the issue didn't come up with the user in the video. I'm trying to figure out the issue using online resources but nothing is solving my problem.

Can you guys help me?

Thanks!

like image 731
Kinan Avatar asked Oct 13 '14 17:10

Kinan


2 Answers

At the top of your controller you'll need to add:

class PinsController < ApplicationController
  respond_to :html, :xml, :json
  ...
end

You can read more about this mime-type on the API Dock

like image 194
Anthony Avatar answered Oct 25 '22 16:10

Anthony


Thanks. Any clues why rails generate scaffold would create "broken" code. Shouldn't that line be added automatically?

like image 37
pca2 Avatar answered Oct 25 '22 15:10

pca2