Hi,
I am trying to make page with a list of users, with a check box next to
each of the user names.
The list of users is given by an array of users : @users
For eg: if @users has {user1, user2,user3} , my page should look like
below.
user1 []
user2 []
user3 []
How can i achieve this? I went thru many howto''s esp to get confused
and
depressed. Please help.
I tried using this:
<form action=''<%= url_for(:controller => "alpha"
,:action =>
"grant_access") %>'' method=''POST''>
check_box("user", user.id, :checked => ''checked''
)
<% end %>
<input type=''submit'' value=''GRANT
ACCESS''/>
<%= pagination_links(@user_pages) %>
</form>
check_box("user", user.id, :checked => ''checked''
) in my rhtml. But it
gets printed directly :(
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Use "[]"''s to send it in the params as a hash like this:
<% @users.each do |user| -%>
<%= check_box(:user, :id, :name => "user[#{user.id}]" -%>
<% end -%>
When this is sent back to the controller, you will have params[:user]
as a hash with user id''s as the keys and 1 as the value.
Sandeep Gudibanda wrote:> Hi,
>
> I am trying to make page with a list of users, with a check box next to
> each of the user names.
> The list of users is given by an array of users : @users
>
> For eg: if @users has {user1, user2,user3} , my page should look like
> below.
>
> user1 []
> user2 []
> user3 []
>
> How can i achieve this? I went thru many howto''s esp to get
confused and
> depressed. Please help.
>
> I tried using this:
>
> <form action=''<%= url_for(:controller =>
"alpha" ,:action =>
> "grant_access") %>''
method=''POST''>
>
> check_box("user", user.id, :checked =>
''checked'' )
>
> <% end %>
>
> <input type=''submit'' value=''GRANT
ACCESS''/>
> <%= pagination_links(@user_pages) %>
>
> </form>
>
> check_box("user", user.id, :checked =>
''checked'' ) in my rhtml. But it
> gets printed directly :(
>
--
Sincerely,
William Pratt
http://www.billpratt.net
billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
2 things I forgot to mention. First, the method passed to check_box (:id
in the below example) is evaluated as an integer and any non-zero value
will check the box. Second, if you use an instance variable named the
same and the name of the checkbox, you can clean things up a bit like this
<% for @user in @users -%>
<%= check_box "user[]", :access_allowed? -%>
<% end -%>
This will achieve the same thing. This example assumes there is a method
for users that denotes whether they have access or not (and whether to
check the box or not). I''m just playing off your example.
William Pratt wrote:> Use "[]"''s to send it in the params as a hash like this:
>
> <% @users.each do |user| -%>
> <%= check_box(:user, :id, :name => "user[#{user.id}]"
-%>
> <% end -%>
>
> When this is sent back to the controller, you will have params[:user]
> as a hash with user id''s as the keys and 1 as the value.
>
> Sandeep Gudibanda wrote:
>
>> Hi,
>>
>> I am trying to make page with a list of users, with a check box next to
>> each of the user names.
>> The list of users is given by an array of users : @users
>>
>> For eg: if @users has {user1, user2,user3} , my page should look like
>> below.
>>
>> user1 []
>> user2 []
>> user3 []
>>
>> How can i achieve this? I went thru many howto''s esp to get
confused and
>> depressed. Please help.
>>
>> I tried using this:
>>
>> <form action=''<%= url_for(:controller =>
"alpha" ,:action =>
>> "grant_access") %>''
method=''POST''>
>>
>> check_box("user", user.id, :checked =>
''checked'' )
>>
>> <% end %>
>>
>> <input type=''submit'' value=''GRANT
ACCESS''/>
>> <%= pagination_links(@user_pages) %>
>>
>> </form>
>>
>> check_box("user", user.id, :checked =>
''checked'' ) in my rhtml. But it
>> gets printed directly :(
>>
>>
>
>
--
Sincerely,
William Pratt
http://www.billpratt.net
billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks a Lot! This worked Great! -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---