开发者

How to save data on dynamically loading form on rails?

开发者 https://www.devze.com 2023-04-12 04:28 出处:网络
I\'m developing a project on rails and It contains form that load dynamic contents but I don\'t know how to get those dynamically generated fields data to save to the database.

I'm developing a project on rails and It contains form that load dynamic contents but I don't know how to get those dynamically generated fields data to save to the database. This is my model

create_table "events", :force => true do |t|
  t.string   "name"
  t.date     "start_at"
  t.date     "end_at"
  t.datetime "created_at"
  t.datetime "updated_at"
  t.string   "trainer_id"
  t.string   "venue_id"
  t.string   "description"
  t.boolean  "holy"
  t.integer  "nxt"
  t.string   "country_id"
end

In my creating new event form I use java script function to load venue selecting drop down menu when user select one country from country drop down menu. When user click submit button it doesn't save the value at dynamically generated ones. How do I solve this problem ?

<%= f.label :country_id %><br />
<%= select :search_, :country_id,
      开发者_如何学编程Country.all.collect { |m| [m.name, m.id] }.sort,
      { :prompt=>'Please Select...' }, :id => 'country_id'
%>

<%= observe_field('country_id',
      :url    => { :controller => 'countries', :action => 'update_city_menu' },
      :update => 'city_field_div',
      :with => "'myval=' + escape(value)"
    )
%>

<div id="city_field_div"></div>

This is the content that loads in to city_field_div:

<% if @country.present? %>
  <select id="neighborhood_field" name="search[venue_field]">
    <%= options_from_collection_for_select(
          Venue.find( :all,
            :order      => "place", 
            :conditions => [ "country_id = ?", session[:countryid]]
          ),
          :id, :place
        ) 
    %>
  </select>
<% end %>

So how to save the data in a dynamically-generated <div> when user clicks the submit button?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号