# Can't update hidden attribute

**URL:** <https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739>\
**Category:** Rails\
**Created:** [March 24, 2009, 2:49pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739 "2009-03-24T14:49:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 24, 2009, 2:49pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/1 "2009-03-24T14:49:01Z")

</div>

Hi,

I want to be able to determine the gender of a person by clicking on a  
picture (a boy and a girl’s face), and it doesn’t work. I can see the  
F or G appear on the screen (when I don’t want that actually because  
it is supposed to be hidden…) but it doesn’t save in the record.

Here is my “new.html.erb” view :

# New member

\<% form\_for(@member) do |f| %\>  
\<%= f.error\_messages %\>

\<%= link\_to\_function(image\_tag("Young M.jpg"), nil, :id =\> "M") do | page| page.replace\_html 'recipient\_gender', "M" end %\>

\<%= link\_to\_function(image\_tag(“Young F.jpg”), nil, :id =\> “F”) do |  
page|  
page.replace\_html ‘recipient\_gender’, “F”  
end %\>

\<% f.hidden\_field :gender %\>

Nickname: \<%= f.text\_field :nickname %\>

\<%= f.submit "Create member" %\>

\<% end %\>

And here are my members\_controller corresponding actions :

def new  
@member = current\_user.members.build(params[:member])  
end

def create  
@member = current\_user.members.build(params[:member])  
if @member.save  
flash[:notice] = ‘member is created.’  
redirect\_to :action =\> ‘index’  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @recipient.errors, :status  
=\> :unprocessable\_entity }  
end  
end

Thank you

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 24, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/2 "2009-03-24T14:51:56Z")

</div>

On 24 Mar 2009, at 13:48, Sacredceltic wrote:

> ```
> end %>
> 
> ```
> 
> \<% f.hidden\_field :gender %\>

Your hidden field isn’t actually inserted into the page at all  
(because you’re using \<% instead of \<%= )

Fred

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 24, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/3 "2009-03-24T15:51:15Z")

</div>

Very well spotted !  
I corrected that but it still doesn’t work…

On Mar 24, 2:51 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 24, 2009, 3:58pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/4 "2009-03-24T15:58:30Z")

</div>

Could you please explain how to do that ?

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 24, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/5 "2009-03-24T15:56:40Z")

</div>

It won’t work anyway.  
In your really clean js code, you’re replacing the content of  
“recipient\_gender” by text (“f” or “m”).  
So, you’re replacing \<input type=“hidden” …\> by “f” or “m” and it  
won’t be submitted to server.

Use labels

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 25, 2009, 8:28am UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/6 "2009-03-25T08:28:19Z")

</div>

any hint ?

Thank you

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 25, 2009, 8:31pm UTC](https://www.ruby-forum.com/t/cant-update-hidden-attribute/163739/7 "2009-03-25T20:31:52Z")

</div>

I tried this :

in my controller :

@male = “M”  
@female=“F”

in my view :

page.replace\_html ‘recipient\_gender’, @male

It doesn’t work either…
