mysql - Rails: simple_form that fills multiple, connected tables -


i have 4 mysql tables should filled @ same time click on simple_form button. in form there input fields existing columns tables. domain table has no id other tables below, others have domain_id in tables. here dependencies:

class domain < activerecord::base     has_many :whitelists     has_many :blacklists     has_many :product_infos end  class whitelist < activerecord::base     belongs_to :domain end  class blacklists < activerecord::base     belongs_to :domain end  class productinfo < activerecord::base     belongs_to :domain end 

my simple_form stored in view of domain.

<%= simple_form_for @domain |f| %>     <%= f.input :name, placeholder: 'example shop' %>     <%= f.input :domain, placeholder: 'http://www.example.com' %>      <h3><b>whitelist</b></h3>     <%= f.input :url_start, as: :text %>     <%= f.input :url_end, as: :text %><br>      <h3><b>blacklist</b></h3>      <%= f.input :url_start, as: :text %>     <%= f.input :url_end, as: :text %><br>      <h3><b>product information</b></h3>     <%= f.input :id_tag %>     <%= f.input :name_tag %>     <%= f.input :product_info_text_tag %><br>      <%= f.button :submit %> <% end %> 

my question how access other columns in view. inputs besides ones domain lead error message (unknown method or local variable). in models quite easy access attributes table, can't behind how works in view.

edit: i've edited form , domain controller. however, still doesn't work. no errors, domain table gets filled.

domain controller:

  def new     @domain = domain.new     @domain.whitelists.build     @domain.blacklists.build     @domain.product_infos.build   end    private     # use callbacks share common setup or constraints between actions.     def set_domain       @domain = domain.find(params[:id])     end      # never trust parameters scary internet, allow white list through.     def domain_params       params.require(:domain).permit(:whitelist_attributes => [:url_start, :url_end], :blacklist_attributes => [:url_start, :url_end], :product_info_attributes => [:id_tag, :name_tag, :promo_price_tag, :price_tag, :shipping_cost_tag, :image_url_tag, :browse_tree_tag, :product_info_text_tag])     end 

according wiki shoul that. add accepts_nested_attributes :whitelists , etc.

<%= simple_form_for @domain |f| %>     <%= f.input :name, placeholder: 'example shop' %>     <%= f.input :domain, placeholder: 'http://www.example.com' %>      <%= f.simple_fields_for :whitelists |w| %>        <%= w.input :url_start, as: :text %>       <%= w.input :url_end, as: :text %>      <% end %>      <%= f.simple_fields_for :blacklists |b| %>        <%= b.input :url_start, as: :text %>       <%= b.input :url_end, as: :text %>      <% end %>      <%= f.simple_fields_for :products |p| %>        <%= p.input :id_tag %>       <%= p.input :name_tag %>       <%= p.input :product_info_text_tag %>     <% end %>         <%= f.button :submit %> <% end %> 

and in controller action, add @domain.whitelists.build , etc.

italic line should be,

@domain.whitelists.build(params[:whitelists]) , on.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -