I am new using rails, I am trying to add to a user form a list of icon
images and the user should select the icon he wants to have as icon.
My problem is that I want to save the selected image in a field from
user called "icon_id", on my user_controller I have de function where
I find all icons @icons = Icon.find(:all)
When I submit the form it doesn''t save the selected radio button in
that field.
I hope someone can help me!
Thanks in advance!!!
My code is:
<%= stylesheet_link_tag ''top'' %>
<%= javascript_include_tag :defaults %>
<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
<div class="boxform">
<div id="formulario">
<fieldset>
<p><label for="login"><%=
_(''Login'') -%></label><br/>
<%= f.text_field :login %></p>
<p><label for="email"><%= _(''Email'')
-%></label><br/>
<%= f.text_field :email %></p>
<p><label for="password"><%=
_(''Password'') -%></label><br/>
<%= f.password_field :password %></p>
<p><label for="password_confirmation"><%=
_(''Confirm Password'') -%></
label><br/>
<%= f.password_field :password_confirmation %></p>
<p> <label> <%= _(''Select the icon you would like to
have if you
don not have a gravatar at gravatars.com:'')%>
</label></p>
<% for icon in @icons %>
<img class="imgicon"
src="/images/top/<%=icon.image%>"/>
<input type="radio" id="icon_id"
name="icon_id" value="<%=icon.id
%>"
<%end%></fieldset>
</div>
<div id="boton">
<button type="submit"><span><em>
<%=_(''Sign Up'') -%> </em></span></
button>
</div>
</div>
<% end -%>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 31 May 2008 14:02:59 Belén wrote:> My problem is that I want to save the selected image in a field > from user called "icon_id", on my user_controller I have de function > where I find all icons @icons = Icon.find(:all) > When I submit the form it doesn''t save the selected radio button in > that field.Whenever your controller doesn''t respond to your parameters as expected, check your development log to see what parameters it received. You''ll probably find a bunch of params like this: { :user => { :login => ''foo'', :email => ''bar'' }, :icon_id => 61 } Notice that icon_id is outside the user hash. So, two problems:> <input type="radio" id="icon_id" name="icon_id" value="<%=icon.id %>"First, you don''t close the input tag. Second, you don''t nest icon_id within the user parameters in the name attribute of the input tag: <input type="radio" id="user_icon_id" name="user[icon_id]" value="<%=icon.id %>" /> Ciao, Sheldon. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIQUhipGJX8XSgas0RAr82AKCln2WHw8wcesJp9UMD0tFKz/+aHACgiea/ hTKGM0OLcmqjCaPQwTCuHIs=pyX/ -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brandon Keepers
2008-May-31 13:38 UTC
Re: Trying to use a radio button as a selection list
Belén, On Sat, May 31, 2008 at 5:02 AM, Belén <bllamasy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am new using rails, I am trying to add to a user form a list of icon > images and the user should select the icon he wants to have as icon. > My problem is that I want to save the selected image in a field from > user called "icon_id", on my user_controller I have de function where > I find all icons @icons = Icon.find(:all) > When I submit the form it doesn''t save the selected radio button in > that field.Sounds like you''re using restful_authentication, which uses attr_accessible to declare which attributes in the user model can be updated. If that''s the case, just add icon_id to the attr_protected declaration in your user model. Brandon -------------------------------------------------------------------------------- Sessions by Collective Idea: Ruby on Rails training in a vacation setting http://sessions.collectiveidea.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you very much! I have done all your suggestions and Now it works !!! On 31 mayo, 14:45, Sheldon Hearn <sheld...-UjuPna88SMAqcZcGjlUOXw@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Saturday 31 May 2008 14:02:59 Belén wrote: > > > My problem is that I want to save the selected image in a field > > from user called "icon_id", on my user_controller I have de function > > where I find all icons @icons = Icon.find(:all) > > When I submit the form it doesn''t save the selected radio button in > > that field. > > Whenever your controller doesn''t respond to your parameters as expected, > check your development log to see what parameters it received. > > You''ll probably find a bunch of params like this: > > { :user => { :login => ''foo'', :email => ''bar'' }, :icon_id => 61 } > > Notice that icon_id is outside the user hash. > > So, two problems: > > > <input type="radio" id="icon_id" name="icon_id" value="<%=icon.id %>" > > First, you don''t close the input tag. > > Second, you don''t nest icon_id within the user parameters in the name > attribute of the input tag: > > <input type="radio" id="user_icon_id" > name="user[icon_id]" > value="<%=icon.id %>" /> > > Ciao, > Sheldon. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.6 (GNU/Linux) > > iD8DBQFIQUhipGJX8XSgas0RAr82AKCln2WHw8wcesJp9UMD0tFKz/+aHACgiea/ > hTKGM0OLcmqjCaPQwTCuHIs> =pyX/ > -----END PGP SIGNATURE-------~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have another question, is there any way I could tell the radio button to check one option as default?? Thanks in advance Belen On 1 jun, 12:11, Belén <bllam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you very much! I have done all your suggestions and Now it > works !!! > > On 31 mayo, 14:45, Sheldon Hearn <sheld...-UjuPna88SMAqcZcGjlUOXw@public.gmane.org> wrote: > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > On Saturday 31 May 2008 14:02:59 Belén wrote: > > > > My problem is that I want to save the selected image in a field > > > from user called "icon_id", on my user_controller I have de function > > > where I find all icons @icons = Icon.find(:all) > > > When I submit the form it doesn''t save the selectedradiobuttonin > > > that field. > > > Whenever your controller doesn''t respond to your parameters as expected, > > check your development log to see what parameters it received. > > > You''ll probably find a bunch of params like this: > > > { :user => { :login => ''foo'', :email => ''bar'' }, :icon_id => 61 } > > > Notice that icon_id is outside the user hash. > > > So, two problems: > > > > <input type="radio" id="icon_id" name="icon_id" value="<%=icon.id %>" > > > First, you don''t close the input tag. > > > Second, you don''t nest icon_id within the user parameters in the name > > attribute of the input tag: > > > <input type="radio" id="user_icon_id" > > name="user[icon_id]" > > value="<%=icon.id %>" /> > > > Ciao, > > Sheldon. > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.6 (GNU/Linux) > > > iD8DBQFIQUhipGJX8XSgas0RAr82AKCln2WHw8wcesJp9UMD0tFKz/+aHACgiea/ > > hTKGM0OLcmqjCaPQwTCuHIs> > =pyX/ > > -----END PGP SIGNATURE-------~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brandon Keepers
2008-Jun-01 18:12 UTC
Re: Trying to use a radio button as a selection list
Belen, On Sun, Jun 1, 2008 at 3:50 AM, Belén <bllamasy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have another question, is there any way I could tell the radio > button to check one option as default?? > Thanks in advance > Belen >2 ways: 1) set the value of the model field to the checkbox value 2) <%= radio_button :model, :field, ''val'', :checked => true %> Brandon -------------------------------------------------------------------------------- Sessions by Collective Idea: Ruby on Rails training in a vacation setting http://sessions.collectiveidea.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you Brandon I have done it this way: <input type="radio" id="user_icon_id" name="user[icon_id]" value="< %=icon.id%>" <%= if icon.id==1 then "checked" end%> style="background- color:#fff; color: #0198ff;" /> On Jun 1, 8:12 pm, "Brandon Keepers" <bran...-NYlJC1mBhkRg9hUCZPvPmw@public.gmane.org> wrote:> Belen, > > On Sun, Jun 1, 2008 at 3:50 AM, Belén <bllam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have another question, is there any way I could tell the radio > > button to check one option as default?? > > Thanks in advance > > Belen > > 2 ways: > > 1) set the value of the model field to the checkbox value > 2) <%= radio_button :model, :field, ''val'', :checked => true %> > > Brandon > > -------------------------------------------------------------------------------- > Sessions by Collective Idea: Ruby on Rails training in a vacation settinghttp://sessions.collectiveidea.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---