Interesting question (possibly)

Coming from the PHP world where such conversations are automatic, I’ll

I meant to say “conversions”

surge wrote:

By the way, is that the
best place to convert @site_id to an integer? Or could it be done
somewhere else? I probably could define the “site_id=()” function
and convert it there.

The way you’ve done it is fine, although the downside is that the
@site_id is actually being stored as a string, so I suppose the ‘proper’
way would be to convert it in a site_id=() function. Its also important
to note that if site_id was an actual field, then it would automatically
be converted to an integer I believe. I suppose its just one of those
small sacrifices you pay when you use such a dynamic language as Ruby.

I’d like to thank everybody and especially you, Dave for helping me
out.

Thanks!!!

You’re very welcome, I hope Rails works out for you :slight_smile:

Dave.

The only thing I can think of is that the function you are using to
produce the list values, Site.list(session[:customer_id]), is returning
the site.id as a string or something, so when the select list is
rendered, it does not match with the equipment.id?

Well, Dave, you did it after all. That’s exactly what it was, only in
the opposite direction. I needed to convert site_id to an integer. My
Site.list looks as follows:

def self.list(customer_id)
find(:all, :conditions => “customer_id = #{customer_id}”).collect
{|p| [p.name, p.id]}
end

So, I think it’s OK. But! When I submit the form, site_id comes in as
a string and attr_writer stores it as a string. So, all that needed to
be done was:

def site_id
if self.building
self.building.site.id
else
@site_id.to_i
end
end

Coming from the PHP world where such conversations are automatic, I’ll
need to remind myself about such issues in Ruby. Which is not a
complaint, just something to watch out for. By the way, is that the
best place to convert @site_id to an integer? Or could it be done
somewhere else? I probably could define the “site_id=()” function
and convert it there.

I’d like to thank everybody and especially you, Dave for helping me
out.

Thanks!!!