Ruby on Rails Thursday, January 3, 2013

On Jan 2, 10:42 pm, JavierQQ <jquari...@gmail.com> wrote:
> Hi everyone,


> end
>
> I'm getting an error there because self.profesion_name is empty, but
> in my log I see that it's being sent and also if I put in my create
> action
>
>        @study = Study.new(params[:study]
> ->     puts @study.to_yaml
>         respond_to
>
> I can see that the object @study has every single attribute filled,
> but inside the profesion_related method in my model, the
> self.profesion_name is empty
>
> What could be wrong with this?
> Hope someone can help

An activerecord object's initialize method basically does

attributes.each do |attr_name, value |
send("#{attr_name}=", value)
end

So at some point it will call self.profession_name = and at some point
it will call self.profession_related but there's no particular order
that is is guaranteed to happen in (on ruby 1.9 I wouldn't be
surprised if it was the order of the fields on the page)

You might want to consider building the profession either outside of
new entirely or in a callback. It's also possible that how you've
modelled it is making it more complicated than it has to be but it's
hard to tell that from here.

Fred
>
> Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment