Webrick Failing with Illegal Instruction

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?

Ben Porterfield wrote in post #960026:

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!

Just drop the index.html.erb part so your block looks like this:

respond_to do |format|
format.html
format.xml { render :xml => @lessons }
end

index.html.erb will already be inferred from the action name, and if
you do want to set it to something different, you would say

respond_to do |format|
format.html { render :template => ‘/foo/bar’ }
format.xml { render :xml => @lessons }
end

Walter

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.

Walter

Awesome, this did indeed fix the problem!

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?

Walter D. wrote in post #960032:

Just drop the index.html.erb part so your block looks like this:

respond_to do |format|
format.html
format.xml { render :xml => @lessons }
end

index.html.erb will already be inferred from the action name, and if
you do want to set it to something different, you would say

respond_to do |format|
format.html { render :template => ‘/foo/bar’ }
format.xml { render :xml => @lessons }
end

Walter

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!

Walter D. wrote in post #960107:

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.

Walter

On Mon, Nov 8, 2010 at 9:46 PM, David K.
[email protected]wrote:

format.xml { render :xml => @lessons }
format.xml { render :xml => @lessons }
end

Oops… did not see that this already got responses.

On Sun, Nov 7, 2010 at 7:51 PM, Ben Porterfield
[email protected]wrote:

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

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” }:

respond_to do |format|
format.html #index.html.erb
format.xml { render :xml => @lessons }
end