How to use checkbox in rails views

39 views
Skip to first unread message

KiranKinuForU

unread,
Feb 6, 2008, 7:04:35 AM2/6/08
to Ruby on Rails: Talk
Hi all,

I want to know how to use checkbox in rails, i.e. how to
access value of particular checkbox in controller....



Regards,
Kiran

polawa...@gmail.com

Nishant Sinha

unread,
Feb 6, 2008, 7:21:17 AM2/6/08
to Ruby on Rails: Talk
Hi Kiran,

your view code like this ;-
<%=check_box_tag('chk_box_name', value = '1', checked = true,
options = {:class=>'class_name'})%>
you can get value in controller like this :-
variable_name=params[:chk_box_name]

Regards,
Nishant
> polawarkir...@gmail.com

Komala Tm

unread,
Jun 5, 2015, 1:16:02 AM6/5/15
to rubyonra...@googlegroups.com
Hi Everyone,

I would like to know how to use multiple checkboxs in rails, i.e. how
to
access the values of those checked boxes..I have requirement like set of
emails and corresponding checkboxes..whenever u select multiple mails i
need to access of those..

please anyone give solution for this

regards,
komala

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jun 5, 2015, 3:47:39 AM6/5/15
to rubyonra...@googlegroups.com
On 5 June 2015 at 06:15, Komala Tm <li...@ruby-forum.com> wrote:
> Hi Everyone,
>
> I would like to know how to use multiple checkboxs in rails, i.e. how
> to
> access the values of those checked boxes..I have requirement like set of
> emails and corresponding checkboxes..whenever u select multiple mails i
> need to access of those..

I asked some questions the first time you asked this, but you did not respond.

Where are you trying to access the values? In the browser or in the
server after posting a form?

You talk about a set of emails, are these records in a table?

Do you have a basic knowledge of Rails, html and javascript or are you
coming at this relatively inexperienced trying to update an existing
app?

Colin
>
> please anyone give solution for this
>
> regards,
> komala
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/56c874da26a2119610bdc24131515090%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Komala Tm

unread,
Jun 5, 2015, 9:33:01 AM6/5/15
to rubyonra...@googlegroups.com
Hi,

I am new to rails.i am taking set of mails from database..my requirment
is
whenever admin select mails from checkboxes..he need to send mails to
those mailids..i have created controller name newsletters..and in index
i have written this code

able class="table table-striped">
<thead>
<tr>
<th></th>
<th>Email</th>
<th>Action</th>
<!-- <th>Location</th>
<th>Description</th> -->

</tr>
</thead>
<tbody>
<% @news.each do |n| %>
<tr>
<td><%=check_box_tag('email_ids[]',n.email,options =
{:class=>'NewsLetter'})%></td>
<td><%=n.email%></td>
<td><%= link_to 'Delete', n, method: :delete, data: { confirm:
'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<%= submit_tag("send") %>
but now i dont know whether i can take those values whenever i ll click
on checkboxes..and how to get those values..how to store it in other
page..here i need to take more than 1 mail id..dont have knowledge about
javascript..please anyone helpme out with the code that what i need to
put it in controller and views..

Colin Law

unread,
Jun 5, 2015, 10:36:21 AM6/5/15
to rubyonra...@googlegroups.com
On 5 June 2015 at 14:32, Komala Tm <li...@ruby-forum.com> wrote:
> Hi,
>
> I am new to rails.i am taking set of mails from database..my requirment
> is
> whenever admin select mails from checkboxes..he need to send mails to
> those mailids..i have created controller name newsletters..and in index
> i have written this code

Firstly I strongly suggest working right through a good tutorial such
as railstutorial.org, including doing all the exercises. That will
give a knowledge of the basics of rails and will allow you to answer
most of your questions yourself.

When you have done that, if you are still having problems then come
back and ask again.

Colin
Reply all
Reply to author
Forward
0 new messages