Ruby on Rails Wednesday, January 2, 2013

It's possible that the profesion_name is not set yet -- you might want to consider creating the Profesion model in a before_save callback. I suspect there are some issues with how this is model, but hopeful this suggestion will get you moving foward.

Cheers, Nicholas



On Wednesday, January 2, 2013 5:42:48 PM UTC-5, JavierQQ wrote:
Hi everyone,

I'm having a weird issue

I have a Study model that has several fields, but to mention a few (or
that ones that I'm having troubles with) are

- profesion_related
- profesion_name

I have this in my controller

def create
  @study = Study.new(params[:study])
  respond_to do |format|
    if @study.save
       #code here
    else
       #more code here
    end
  end
end

and in my model

class Study < AR....
  #there are other attr_accessible but just wanted to show this
  attr_accessible :profesion_related
  attr_accessor :profesion_related

  def profesion_related=(id)
    profesion_parent = Profesion.find(id)
    ######below here the last attribute is the one that is empty
    new_profesion = Profesion.create({m_code: profesion_parent.m_code,
g_code: profesion_parent.g_code, name: self.profesion_name})
  end

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 me

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.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/v16q-i3UrTYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment