what error u r getting? On Mon, Sep 29, 2008 at 11:32 AM, Indu Rs <[EMAIL PROTECTED]>wrote:
> > Hello everyone > Just started to learn ROR.Does anyone have an idea on how to store > fields in two tables using a single form? > I wish to store the registration details in 'users' table and the > langauges selected by the user in another table user_language with each > row for one language selected(fields in the user_language table is > user_id and language_id where user_id is the id of the user trying to > register ie there may be more than one languages for a single user) > My view is like the following > <% form_for :user do |f| %> > <tr> > <td>Enter Name</td> > <td>:</td> > <td><%= f.text_field :name %> > </tr> > <tr> > <td>Enter Username</td> > <td>:</td> > <td><%= f.text_field :username %> > </tr> > <tr> > <td>Enter Password</td> > <td>:</td> > <td><%= f.password_field :password %> > </tr> > <tr> > <td>Address</td> > <td>:</td> > <td><%= f.text_field :address %> > </tr> > > <tr> > <td>Select Gender</td> > <td>:</td> > <td><%= radio_button("user", "gender", "1") %>Male > <%= radio_button("user", "gender", "2") %>Female > <%= radio_button("user", "gender", "3") %>Not Applicable > </td> > </tr> > <tr> > <td>Select Languages Known</td> > <td>:</td> > <td> > <% for language in @languages %> > > <%= language.language %> <%= > check_box_tag("user_language[language_id][]","#{language.id}") %> > <% end %> > > </td> > </tr> > <tr> > <td>Select country </td> > <td> :</td> > <td> > <select id="user[country_id]" name="user[country_id]"> > <option value="">Select Country </option> > <%= options_from_collection_for_select( > Country.find(:all), "id", "name") %> > </select> > </td> > </tr> > <tr> > <td> Select State</td> > <td>:</td> > <td> > <div id="state_list"> > <%= select("user", "state_id", State.find(:all).collect{ |c| [ > c.state, c.id] }, {:prompt => 'Select > State'},{:onchange=>'display_msg();'}) %> > > <%= observe_field("user[country_id]", > :frequency => 0.50, > :update => "user_state_id", > :url => {:action => :load_states}, > :with => "'country_id='+value") > %> > </div> > </td> > </tr> > > <tr> > <td colspan="3" align="center"> > <%= f.submit "Register" > ,{:onclick=>"display_msg(document.getElementById('user_name').value)" > }%> > <%= f.submit "List Users" %> > </td> > </tr> > <% end %> > > Controller contains > def create > @languages = Language.find(:all) > if request.post? and params[:commit] == "Register" > @user = User.new(params[:user]) > > @user.save > @user.user_language = User_Language.new(params[:user_language]) > redirect_to :action => 'list_users' > end > when trying an error occurs . Pls help! > -- > 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---