simple question

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 %><br />     <% 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

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 Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

big poppa wrote:

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 %><br />     <% 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?

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

HTH

~Matt