On Thu, Jul 8, 2010 at 11:23 AM, Deepak Kamath <dk87...@gmail.com> wrote:
> I am using radio button in my form .... how can i store the value of radio > button in database .. my code is > > > <%= radio_button_tag(:users,"yes") %> > <%=label_tag(:approved,"YES") %> <br /> > > Radio button ll be generated ..but how to store yes into 'appoved' field in > database > Deepak, The value of this radio button will be submitted to the server as - iirc - users[yes]. So in the controller, this value would be accessible as params[:users][:yes]. The usual way of creating and handling forms in Rails is to expose instance variables from an ActiveRecord object through a form builder object, like this: <% form_for(@user) do |f| -%> <%= f.text_field :email -%> <% end -%> This will create a form tag with the relevant action and method, along with a single field referencing the user's email address. When you submit this form to the controller, the entire set of variables for the user can be referenced as params[:user], and the single value as params[:user][:email]. Since these are all instance variables, Rails lets you set values in the object directly, ie: @user.update_attributes(params[:user]) @user = User.create(params[:user]) The xxx_button_tag and similar are very rarely used in Rails these days. There's some decent documentation on Rails' form helpers here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html Cheers, - Marius -- To post to this group, send email to gitorious@googlegroups.com To unsubscribe from this group, send email to gitorious+unsubscr...@googlegroups.com