I've just started a new rails project (3.0.1, ruby 1.9.2 on Mac OS X),
and have a few parts of it built out. I've just created new
controller/views using rails g scaffold_controller Lesson, and then
added a route to routes.rb with "resources :lessons"
Now, when i go to /lessons, Webrick fails with "Illegal instruction"
The controller function getting hit is lessons#index, and looks like
this:
# GET /lessons
# GET /lessons.xml
def index
@lessons = Lesson.all
respond_to do |format|
format.html index.html.erb
format.xml { render :xml => @lessons }
end
end
If i comment out the respond_to section, the index page renders fine
with no crashing. I have no idea what I could have done to make it begin
to crash with respond_to? This is the first time i've used "resources"
in my app. What can I do to even start to debug this issue? Thanks!
With additional testing I've found that anywhere i put format.html in a
respond_to block, I get the same error. Any thoughts on how I can start
to track this down?
However, I didn't write the format code - this code was generated with:
rails g scaffold_controller Lessons
Which leads me to believe that this is the proper format code....3.0.1
generates "format.html {filename}.html.erb" for each controller function
- is this a generator bug, or do I have a problem with my system?
That may indeed be the new Rails 3 syntax, I haven't spent any time with that yet, so sorry if I led you astray. But I suspect your problems began when you used the plural name for your scaffold argument. Try again, using rails g scaffold_controller Lesson and see if there is a different output.
It's even simpler than that. Chalk it up to a rails newbie - sorry for
the bother. Here's what I did:
Rails generated this:
# GET /appointments/1
# GET /appointments/1.xml
def show
@appointment = Appointment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @appointment }
end
end
I had made a few changes, but then was undoing them - I must have
thought that I had made those comments after format.html and uncommented
them myself.Bah!
I think you need to comment out index.html.erb… should not be there, or if you want to specify it, it should be a string or something like { render :action => “index” }:
I think you need to comment out index.html.erb… should not be there, or if you want to specify it, it should be a string or something like { render :action => “index” }: