Undefined method `call' for nil:NilClass

why would I be getting this error after submitting my form?

NoMethodError in EchantillonsController#create
undefined method `call’ for nil:NilClass

This is my create method in the controller:

def create

@echantillon = Echantillon.new(params[:echantillon])
@echantillon.set_eros_values

respond_to do |format|
  if @echantillon.save
     if params[:echantillon][:vignette].blank?
        format.html { redirect_to(@echantillon) }
        format.xml  { render :xml => @echantillon, :status

=> :created, :location => @echantillon }
else
render :action => “location”
end
else
format.html { render :action => “new” }
format.xml { render :xml => @echantillon.errors, :status
=> :unprocessable_entity }
end
end
end

Hi

why would I be getting this error after submitting my form?

NoMethodError in EchantillonsController#create
undefined method `call’ for nil:NilClass

Can’t say from this what caused error. Please paste in which line error
happened and what is there on that line.

Just a guess only

     if params[:echantillon][:vignette].blank?

instead of this please try

unless params[:echantillon][:vignette]

Sijo

I think only two lines could cause this

@echantillon.set_eros_values
  if @echantillon.save

Which line does it say the error comes from in your output?

You could write some

Rails.logger.debug “Hi, this is the current status:
#{@echantillon.inspect}”

between every line and then watch your logs/development.log to see
where exactly it breaks.

I would guess on set_eros_values (whatever that function is supposed
to do :slight_smile:

The cause of this error is on this line:

     else
        render :action => "location"
     end

It should be:

else
format.html {render :action => ‘location’}
end

When using respond_to, the format of the response is required for any
render or redirect_to methods. :slight_smile: