Ruby on Rails Wednesday, January 2, 2013

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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment