In one of my Controllers I stumbled upon a really strange error. On render :action => :create I get this error message:
NoMethodError in Admin/machines/baseController#save undefined method `to_str' for [:action, :create]:Array
Application Trace: /usr/local/lib/ruby/gems/1.8/gems/map_by_method-0.7.0/lib/ map_by_method.rb:12:in `method_missing' vendor/rails/actionpack/lib/action_controller/layout.rb:241:in `to_s' vendor/rails/actionpack/lib/action_controller/layout.rb:241:in `render_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render' app/controllers/admin/machines/base_controller.rb:22:in `save'
I've done rendering actions probably a hundred times before and I don't see anything wrong with my code. But just for good measure here's the code I'm using. When saving fails because of some validation errors it is supposed to render the create view again but dies with the above error message.
class Admin::Machines::BaseController < ApplicationController def create @machine = Machine::Base.new @picture = Picture.new end
def save @machine = Machine::Base.new(params[:machine]) @picture = Picture.new(params[:picture]) @machine.picture = @picture if @machine.save && @picture.save flash[:notice] = "yay!" redirect_to :action => :index else flash[:error] = "nay" render :action => :create end end end
Cheers Martin