# undefined method \`with\_indifferent\_access' for "":String

**URL:** <https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807>\
**Category:** rubyonrails-talk\
**Created:** [August 16, 2012, 6:20pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807 "2012-08-16T18:20:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 16, 2012, 6:20pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/1 "2012-08-16T18:20:14Z")

</div>

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

&nbsp;&nbsp;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| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 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.

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [August 16, 2012, 8:38pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/2 "2012-08-16T20:38:07Z")

</div>

> 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
> 
> &nbsp;&nbsp;current\_contribuyente.comps.build(params[:comp]).valid?

What is current\_contribuyente?

Colin

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 16, 2012, 8:48pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/3 "2012-08-16T20:48:18Z")

</div>

Colin Law wrote in post #1072606:

> What is current\_contribuyente?
> 
> Colin

current\_contribuyente is a method that works similar to current\_user work like these:

def current\_contribuyente &nbsp;&nbsp;current\_user.contribuyente end

it just a custom current\_user that retrieves a model (contribuyente) for the current\_user

contribuente has\_many :comps

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 17, 2012, 11:34am UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/4 "2012-08-17T11:34:06Z")

</div>

arturo drlt wrote in post #1072587:

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 17, 2012, 7:25pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/5 "2012-08-17T19:25:17Z")

</div>

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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= collection\_select(:comp, :comp\_emis\_regs\_reg\_fil, current\_contribuyente.contribuyente\_regs, :reg\_fil, :reg\_fil, {:include\_blank =\> false}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 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?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 17, 2012, 9:31pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/6 "2012-08-17T21:31:16Z")

</div>

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})

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [August 17, 2012, 11:18pm UTC](https://discuss.rubyonrails.org/t/undefined-method-with-indifferent-access-for-string/64807/7 "2012-08-17T23:18:14Z")

</div>

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?
