aris
August 16, 2012, 8:20pm
1
Hi
I’m having a issue with one object when try to update the attributes in
this object previously saved in the database
I have one object comp and one object reg they have this relationship
comp
has_many regs
reg
belongs_to comp
when run use the method valid? like this
current_contribuyente.comps.build(params[:comp]).valid?
it returns: IndexError (string not matched)
And when I try to update directly the comp directly it return this
error:
@comp = current_contribuyente.comps.find(params[:id])
@comp.update_attributes (params[:comp])
NoMethodError (undefined method `with_indifferent_access’ for
“”:String):
This is the code from the view where I create this elements
= form_for @comp , :html => {:id => “new_form”, :onsubmit => “return
validate_form()”}, :remote => true do |f|
= f.fields_for :comprobante_emis_regs_attributes do |cer|
= cer.collection_select :reg_fil,
current_contribuyente.contribuyente_regs, :reg_fil, :reg_fil,
{:include_blank => false}, :class => ‘reg_fil’, :name =>
“comp[comp_emis_regs_attributes][0][reg_fil]”
Somebody has run into this issue i’m really running out of ideas of how
to fix this.
On 16 August 2012 19:20, arturo drlt [email protected] wrote:
reg
belongs_to comp
when run use the method valid? like this
current_contribuyente.comps.build(params[:comp]).valid?
What is current_contribuyente?
Colin
Colin L. wrote in post #1072606:
On 16 August 2012 19:20, arturo drlt [email protected] wrote:
What is current_contribuyente?
Colin
current_contribuyente is a method that works similar to current_user
work like these:
def current_contribuyente
current_user.contribuyente
end
it just a custom current_user that retrieves a model (contribuyente) for
the current_user
contribuyente has_many :comps
arturo drlt wrote in post #1072587:
Hi
I’m having a issue with one object when try to update the attributes in
this object previously saved in the database
I have one object comp and one object reg they have this relationship
comp
has_many regs
reg
belongs_to comp
when run use the method valid? like this
current_contribuyente.comps.build(params[:comp]).valid?
it returns: IndexError (string not matched)
And when I try to update directly the comp directly it return this
error:
@comp = current_contribuyente.comps.find(params[:id])
@comp.update_attributes (params[:comp])
NoMethodError (undefined method `with_indifferent_access’ for
“”:String):
This is the code from the view where I create this elements
= form_for @comp , :html => {:id => “new_form”, :onsubmit => “return
validate_form()”}, :remote => true do |f|
= f.fields_for :comprobante_emis_regs_attributes do |cer|
= cer.collection_select :reg_fil,
current_contribuyente.contribuyente_regs, :reg_fil, :reg_fil,
{:include_blank => false}, :class => ‘reg_fil’, :name =>
“comp[comp_emis_regs_attributes][0][reg_fil]”
Somebody has run into this issue i’m really running out of ideas of how
to fix this.
Hi arturo drlt,
Try without “fields_for”
It really works!
Regards,
Peter
Sorry i wrote a wrong error the collection_select return this error
undefined method `comprobante_emis_regs_reg_fil’ for
#Comp:0x7f90f6298ae0
collection_select(:comp, :comp_emis_regs_regimen_fiscal,
current_contribuyente.contribuyente_regs, :reg_fil, :reg_fil,
{:include_blank => false})
Peter p. wrote in post #1072655:
arturo drlt wrote in post #1072587:
Hi arturo drlt,
Try without “fields_for”
It really works!
Regards,
Peter
I always had troubles writing the code for this model using only
collection_select
so far i have this code:
if comp_exist
= collection_select(:comp, :comp_emis_regs_reg_fil,
current_contribuyente.contribuyente_regs, :reg_fil, :reg_fil,
{:include_blank => false})
- else
= collection_select(:contribuyente,
:contribuyente_regs_reg_fil, current_contribuyente.contribuyente_regs,
:reg_fil, :reg_fil, {:include_blank => false}, {:class => ‘reg_fil’,
:name => “comp[comp_emis_regs_attributes][0][reg_fil]”})
and the first collection_select return this error
undefined method `comp_emis_regs[0].reg_fil’ for #Comp:0x7f90f655ca38
because the method :comp_emis_regs_reg_fil its really one array and i
don’t know how to specify the method for the reg_fil attribute inside
:comp_emis_regs because the relationship is has_many, some ideas?
UPDATE
code:
collection_select(:comp, :comp_emi_reg_ids, CompEmiReg.where(“comp_id =
?”, @comp.id ), :id, :reg_fil, {:include_blank => false})
return this error
NoMethodError (undefined method `with_indifferent_access’ for
“”:String):
and this code:
collection_select(:comp, :comp_emi_reg_ids, CompEmiReg.where(“comp_id =
?”, @comp.id ), :reg_fil, :regi_fil, {:include_blank => false})
return this error:
ActiveRecord::RecordNotFound (Couldn’t find CompEmiReg with ID=0):
I tried to do this
collection_select(:comp, :comp_emi_reg_regs_fils,
CompEmiReg.where(“comp_id = ?”, @comp.id ), :reg_fil, :regi_fil,
{:include_blank => false})
but it don’t wokrs it returns:
NoMethodError: undefined method `comp_emi_reg_regs_fils’ for
#Comp:0x7ffd398b58d8
it seems that in the param of method for collection I only can send the
attribute id in plural other fields just return NoMethodError, I don’t
know what I’m doing wrong at the end always end up with NoMethodError
(undefined method `with_indifferent_access’ for “”:String):
somebody knows another way to do this or knows if in the param method it
only can receive ids for this kind of relationship?