Please, how I use checkbox? In database the field is a INT(1), if it is 1 the checkbox in* edit form* will be checked and if it is 0 the checkbox will bi unckecked... How implement this? I''m using: <% if 1==@media.published %> <p><input type="checkbox" name="media[published]" value="1" checked/><label for="media_published">Published?</label></p> <% else %> <p><input type="checkbox" name="media[published]" value="1" /><label for="media_published">Published?</label></p> <% end %> But it really not look''s good. -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On Apr 11, 2005 11:25 AM, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > Please, how I use checkbox? > In database the field is a INT(1), if it is 1 the checkbox in* edit > form* will be checked and if it is 0 the checkbox will bi unckecked... > How implement this? > I''m using: > <% if 1==@media.published %> > <p><input type="checkbox" name="media[published]" value="1" > checked/><label for="media_published">Published?</label></p> > <% else %> > <p><input type="checkbox" name="media[published]" value="1" /><label > for="media_published">Published?</label></p> > <% end %> > But it really not look''s good. >This isn''t really good either, but you could do <% checked = @media.published == 1 ? "checked" : "" %> <input type="checkbox" name="media[published]" value = "1" <%= checked %> >
Try <%= check_box("media", "published") %> See http://rails.rubyonrails.com/classes/ActionView/Helpers/ FormHelper.html#M000318 for more information. On Apr 11, 2005, at 1:25 PM, Pedro Valentini wrote:> > Please, how I use checkbox? > In database the field is a INT(1), if it is 1 the checkbox in* edit > form* will be checked and if it is 0 the checkbox will bi unckecked... > How implement this? > I''m using: > <% if 1==@media.published %> > <p><input type="checkbox" name="media[published]" value="1" > checked/><label for="media_published">Published?</label></p> > <% else %> > <p><input type="checkbox" name="media[published]" value="1" /><label > for="media_published">Published?</label></p> > <% end %> > But it really not look''s good. > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> writes:> In database the field is a INT(1), if it is 1 the checkbox in* edit > form* will be checked and if it is 0 the checkbox will bi unckecked... > How implement this? > I''m using: > <% if 1==@media.published %>How about <%= check_box(''media'', ''published'') %> ? -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
<%= check_box("media", "published") %> Also, see http://wiki.rubyonrails.com/rails/show/HowtoUseBooleanColumns for your checks <% if @media.published? %> Joe Van Dyk wrote:>On Apr 11, 2005 11:25 AM, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>Please, how I use checkbox? >>In database the field is a INT(1), if it is 1 the checkbox in* edit >>form* will be checked and if it is 0 the checkbox will bi unckecked... >>How implement this? >>I''m using: >><% if 1==@media.published %> >><p><input type="checkbox" name="media[published]" value="1" >>checked/><label for="media_published">Published?</label></p> >><% else %> >><p><input type="checkbox" name="media[published]" value="1" /><label >>for="media_published">Published?</label></p> >><% end %> >>But it really not look''s good. >> >> >> > >This isn''t really good either, but you could do > ><% checked = @media.published == 1 ? "checked" : "" %> ><input type="checkbox" name="media[published]" value = "1" <%= checked %> > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >