Nil object on post - but commit information is not empty?

Hello Rails folks,
I am trying to roll my own widget and I’m having trouble when the data
gets POSTed. My widget is basically three select boxes strung together
to create one big string when the data gets submitted.

The TypeError message I get is “can’t convert nil into String” - but
when I look at the parameters, they all appear to be defined. Maybe
someone can enlighten me?

Here is the information:

app/controllers/calendar_controller.rb:30:in +' app/controllers/calendar_controller.rb:30:increate’

Controller: the offending line in my ‘create’ method:

@event.start_time = params[:event_st][:st_hrs] +

params[:event_st][:st_mins] + params[:event_st][:ampm]

View Code:

Start time
<%= select(:event_st, :st_hrs, hours) %> <%= select(:event_st, :st_mins, %w(00 15 30 45)) %> <%= select(:event_st, :st_ampm, %w(am pm)) %>

The Model is called Event and doesn’t do anything special. But it has a
“start_time” attribute that I would like to write to.

Here is what is in the params when I hit “Create”:

Parameters: {“commit”=>“Create”, “event”=>{“end_date(3i)”=>“20”,
“title”=>“test”, “start_date(1i)”=>“2007”, “start_date(2i)”=>“12”,
“start_date(3i)”=>“20”, “description”=>“test”, “end_date(1i)”=>“2007”,
“end_date(2i)”=>“12”, “end_time”=>“d”}, “event_st”=>{“st_hrs”=>“1”,
“st_ampm”=>“am”, “st_mins”=>“00”}}

Any help would be greatly appreciated! I’ve spent a number of hours now
digging around in the Rails API, my AWDWR book, Rails Recipes, but I
couldn’t seem to find the information I was looking for on how to
accomplish what I need.

Thanks,
kodama

Hello,

I think your referencing the “ampm” parameter incorrectly. Try this:

@event.start_time = params[:event_st][:st_hrs] + params[:event_st]
[:st_mins] + params[:event_st][:st_ampm]

Cheers,
Anthony

On Dec 20, 12:35 am, Old E. [email protected]

D’oh. That’ll teach me to read my code more carefully once I’m working
past midnight. :slight_smile:

Thanks a lot Anthony!

Anthony Franco wrote:

Hello,

I think your referencing the “ampm” parameter incorrectly. Try this:

@event.start_time = params[:event_st][:st_hrs] + params[:event_st]
[:st_mins] + params[:event_st][:st_ampm]

Cheers,
Anthony

On Dec 20, 12:35 am, Old E. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs