Paul Jonathan Thompson
2006-Jul-19 05:47 UTC
[Rails] Howto: Check_box with a variable (no model)
Hi, I would like to put a checkbox on a form where the input field is a variable rather than a field in a model. The normal way (with a model) would be: <%= check_box(''client'', ''accept'', {}, "1", "0") %> But since accept is a variable @accept and model client will not be there, how do I make a check box work? Regards, Paul
Paul Jonathan Thompson wrote:> Hi, > > I would like to put a checkbox on a form where the input field is a > variable rather than a field in a model. > > The normal way (with a model) would be: > > <%= check_box(''client'', ''accept'', {}, "1", "0") %> > > But since accept is a variable @accept and model client will not be > there, how do I make a check box work?Generally, you would use the same helper, but with _tag appended. So in this case, check_box_tag. It is detailed here : http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000500 (well, the documentation is pretty sparse on this particular helper - but you should be able to figure it out. Regards, Henning Kilset Railsfoundry.com
Paul Jonathan Thompson wrote:> Hi, > > I would like to put a checkbox on a form where the input field is a > variable rather than a field in a model. > > The normal way (with a model) would be: > > <%= check_box(''client'', ''accept'', {}, "1", "0") %> > > But since accept is a variable @accept and model client will not be > there, how do I make a check box work? > > Regards, > > PaulHi Pail, I hope this helps but this is how we did it: <% $findrecord.each do |$findrecord| %> <% $array = TableRecords.find_by_sql(["select * from table_records where id = ?", $findrecord.id]) $recordrow = $array[0] $recordid = $recordrow.id.to_s $recordemail = $recordrow.email%> <br /><%= check_box ("checker", "#{$recordid}", {}, "yes", "no") %> <%=$recordemail%> <% end %><br> thanks, Bing -- Posted via http://www.ruby-forum.com/.
Oops, obviously I wasn''t reading the premise quite clearly, well, just have the check_box make a loop as many times as you want and you can pass a variable into the second field on the check_box helper. I hope that was of any help. thanks, Bing -- Posted via http://www.ruby-forum.com/.
Henning Kilset
2006-Jul-19 22:30 UTC
[Rails] Re: Howto: Check_box with a variable (no model)
Bing Tan wrote:> Oops, > > obviously I wasn''t reading the premise quite clearly, well, just have > the check_box make a loop as many times as you want and you can pass a > variable into the second field on the check_box helper. >I think using check_box_tag would be a LOT easier, but that is just me :) -- Henning Kilset Rails Foundry http://railsfoundry.com/
Paul Jonathan Thompson
2006-Jul-19 23:13 UTC
[Rails] Re: Howto: Check_box with a variable (no model)
Hi, Thanks for the help. I used check_box_tag and it worked just fine. Regards, Paul On 20/07/06, Henning Kilset <henning@railsfoundry.com> wrote:> Bing Tan wrote: > > Oops, > > > > obviously I wasn''t reading the premise quite clearly, well, just have > > the check_box make a loop as many times as you want and you can pass a > > variable into the second field on the check_box helper. > > > I think using check_box_tag would be a LOT easier, but that is just me :) > > -- > Henning Kilset > Rails Foundry > http://railsfoundry.com/ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Richard Sandilands
2006-Jul-20 00:46 UTC
[Rails] Re: Howto: Check_box with a variable (no model)
On 7/20/06, Paul Jonathan Thompson <rails001@gmail.com> wrote:> Thanks for the help. I used check_box_tag and it worked just fine.When I need a user to tick a "terms & conditions" checkbox, I use a check_box helper but in the model do ''validates_acceptance_of :terms'' even though terms is not a field in the database. I realise you don''t have a corresponding model, but thought I''d throw this in.