Forum: Ruby on Rails Fetching checkbox name from database

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
41c00c6fc642a9dd55f8745d9afc08e1?d=identicon&s=25 Navi023 (Guest)
on 2008-12-10 14:01
(Received via mailing list)
Hi all, I am new to this place and ruby on rails as well.

I am developing a web application where I have to create a form which
displays the checkboxes. The names of these checkboxes have to be
fetched from a database. Can some one help me out of this ?
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2008-12-10 14:13
<%= check_box :modelname, :attribute, options, on_value, off_value %>



Example:

check_box "post", "validated"   # post.validated? returns 1 or 0
    <input type="checkbox" id="post_validate" name="post[validated]"
           value="1" checked="checked" />
    <input name="post[validated]" type="hidden" value="0" />

check_box "puppy", "gooddog", {}, "yes", "no"
    <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]"
value="yes" />
    <input name="puppy[gooddog]" type="hidden" value="no" />

Just use it..
If you can't understand, get back again
41c00c6fc642a9dd55f8745d9afc08e1?d=identicon&s=25 Navi023 (Guest)
on 2008-12-11 04:50
(Received via mailing list)
currently i am using this in my view, which makes it pretty hard
coded...can u suggest something else in place of it(which dynamically
fetches the checkbox names from a database)

Also, I want to use two databases(one for fetching the checkbox names,
and the other is for my application). Do I need to include some extra
code for it?

<html>
<head>
<title>Subscribe</title>
</head>
<body>
<h2>Subscribe</h2>

<% form_for :user do |form| %>

<fieldset>
<legend>Enter Your Details</legend>


<label for="%parameter1">Parameter1:</label>
<%= form.check_box :parameter1 %>
</br>
<label for="%parameter2">Parameter2:</label>
<%= form.check_box :parameter2 %>
</br>
<label for="%parameter3">Parameter3:</label>
<%= form.check_box :parameter3 %>
</br>
<%= submit_tag "Subscribe!", :class => "submit" %>
</fieldset>
<% end %>


</body>
</html>


On Dec 10, 6:13 pm, Priya Buvan <rails-mailing-l...@andreas-s.net>
41c00c6fc642a9dd55f8745d9afc08e1?d=identicon&s=25 Navi023 (Guest)
on 2008-12-11 10:48
(Received via mailing list)
some one please help me out. :(
41c00c6fc642a9dd55f8745d9afc08e1?d=identicon&s=25 Navi023 (Guest)
on 2008-12-13 11:05
(Received via mailing list)
Anyone out there? please have a look at my query also. :(
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-13 18:22
(Received via mailing list)
On Wed, Dec 10, 2008 at 7:49 PM, Navi023 <navneet030325@gmail.com>
wrote:
>
> currently i am using this in my view, which makes it pretty hard
> coded...can u suggest something else in place of it(which dynamically
> fetches the checkbox names from a database)
>
> Also, I want to use two databases(one for fetching the checkbox names,
> and the other is for my application). Do I need to include some extra
> code for it?

The doc for ActiveRecord::Base has a section titled
  "Connection to multiple databases in different models"

Perhaps that would be a good place to start :-)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
This topic is locked and can not be replied to.