I am working on Address book and i face problem regarding how to added
dynamic column by each user. Each user display its own
column. How to submit all multiple record inside one form.

 view (e.g consider mike is user and its create name,city and address
dynamic  column how three row inserted into database. )

<h1>Add Field values</h1>

<%= form_for(:detail, :url => {:controller => 'details', :action =>
'create'})  do |f| %>

  <% @info.each do |a| %>
    <%= f.hidden_field :columns_id, :value =>a.id   %>
     <p>
      <td><%= a.value %></td>
      <td><%= f.text_field :column_value %></td>
    </p></br>
  <% end %>

  <%= f.hidden_field :users_id, :value => current_user.id  %>
  <p class="button"><%= f.submit %></p>

<% end %>


controller


class DetailsController < ApplicationController
  def new
      @detail = Detail.new
       @info = Column.where(:users_id => current_user.id).all
  end

  def create
    @detail = Detail.new(user_params)
    if @detail.save
      redirect_to new_detail_path, :notice => "Added Sucessfully!"
     else
      render "new"
    end
  end

private

  def user_params
      params.require(:detail).permit(:users_id,:column_value,:columns_id)
  end
end


Database structure

CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"email" varchar(255), "password_hash" varchar(255), "password_salt"
varchar(255), "created_at" datetime, "updated_at" datetime);

CREATE TABLE "columns" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"value" varchar(255), "created_at" datetime, "updated_at" datetime,
users_id integer REFERENCES users (id));

CREATE TABLE "details" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"users_id" integer, "column_value" varchar(255), "created_at" datetime,
"updated_at" datetime, columns_id integer REFERENCES columns (id));

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d777dc9fb46e610d707484b5f8cf35d6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to