# Simple question

**URL:** <https://www.ruby-forum.com/t/simple-question/166307>\
**Category:** Rails\
**Created:** [April 23, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/simple-question/166307 "2009-04-23T19:03:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/0ea827/32.png) [@cbnewman](https://www.ruby-forum.com/u/cbnewman)\
**Post date:** [April 23, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/simple-question/166307/1 "2009-04-23T19:03:31Z")

</div>

I apologize for the embarrassingly simplistic nature of this question,  
but I’m new to Ruby/Rails.

From within a html.erb file, what is the syntax for assigning a value  
to a parameter? For example, when a specific form is used, the  
following attribute (make\_this\_true) should always be 1

\<% form\_for(@foo) do |f| %\>  
\<%= f.error\_messages %\>  
…  
\<%= f.label :make\_this\_true %\>  
  
\<% foo.make\_this\_true = 1 %\>

but I don’t have to tell the readers of this group that the above code  
is garbage.

1. is there an easy way to set this attribute? If so, what is the  
syntax?
2. My first attempt at solving this problem involved using a check box  
or a radio button that defaulted to “true” but this turned out to be  
non-intuitive as well. I then realized that the user should not need  
to interact with this variable here.
3. Perhaps making the default value of this variable true in the  
database schema? Any tips on that route?

Sorry for the long-windedness and simplistic nature of this question.

–b

---

<div class="post-metadata">

**Author:** ![cbnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/0ea827/32.png) [@cbnewman](https://www.ruby-forum.com/u/cbnewman)\
**Post date:** [April 23, 2009, 10:41pm UTC](https://www.ruby-forum.com/t/simple-question/166307/2 "2009-04-23T22:41:26Z")

</div>

big poppa wrote:

> \<%= f.label :make\_this\_true %\>  
>   
> to interact with this variable here.  
> 3. Perhaps making the default value of this variable true in the  
> database schema? Any tips on that route?

I’d do it with a hidden field, others may be able to recommend something  
else though.

HTH

~Matt

---

<div class="post-metadata">

**Author:** ![cbnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/0ea827/32.png) [@cbnewman](https://www.ruby-forum.com/u/cbnewman)\
**Post date:** [April 23, 2009, 10:43pm UTC](https://www.ruby-forum.com/t/simple-question/166307/3 "2009-04-23T22:43:58Z")

</div>

I’d go for a hidden field too.

---

<div class="post-metadata">

**Author:** ![cbnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/0ea827/32.png) [@cbnewman](https://www.ruby-forum.com/u/cbnewman)\
**Post date:** [April 23, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/simple-question/166307/4 "2009-04-23T23:47:36Z")

</div>

On Apr 23, 2009, at 1:02 PM, big poppa wrote:

> \<%= f.label :make\_this\_true %\>  
>   
> to interact with this variable here.  
> 3. Perhaps making the default value of this variable true in the  
> database schema? Any tips on that route?
> 
> Sorry for the long-windedness and simplistic nature of this question.
> 
> –b

In your controller:

new:  
@foo = Foo.new(:make\_this\_true =\> true)  
new.html.erb  
\<%= f.hidden :make\_this\_true %\>

or, create:  
@foo = Foo.new(params[:foo]) {|f| f.make\_this\_true = true }

Having a default in the DB schema is likely a good idea,too. If this  
is actually a boolean, having :default=\>true,:null=\>false keeps you  
from dealing with NULL values in the database.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
