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!
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
Thanks. Any clues why rails generate scaffold
would create "broken" code. Shouldn't that line be added automatically?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With