Rails - nested model input data not appearing in "show" page -


i having trouble figuring out how make data collected through nested model appear on "show" page. have rails app 3 models, user model, project model, , team model. model associations follows:

project:-

class project < activerecord::base    has_many :users, :through => :team   has_one :team, :dependent => :destroy      accepts_nested_attributes_for :team, allow_destroy: true  end 

team:-

class team < activerecord::base      belongs_to :project     has_many :users  end 

user:-

class user < activerecord::base   # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable     has_and_belongs_to_many :teams   end 

every project has 1 team, , every team consists of many users saved in database. make possible select multiple existing users within project form (through nested form) , save them model called team. managed form working correctly, im not sure how go saving data collected team model, , make group of users selected (the team) appear in project's show page. please help!

p.s used nested form gem add multiple team members within project's form.

projects show page:-

<%= bootstrap_nested_form_for(@project, :html => {:multipart => true}, layout: :horizontal)   |f| %>     <% f.fields_for :teams |builder| %>   <% if builder.object.new_record? %>    <%= builder.collection_select :user, user.all, :id, :email, { prompt: "please select", :selected => params[:user], label: "employee" } %>    <% else %>    <%= builder.hidden_field :_destroy %>   <%= builder.link_to_remove "remove" %>    <% end %>  <%= f.link_to_add "add team member", :teams %>     <%= f.submit %> <% end %> 

projects controller:-

class projectscontroller < applicationcontroller   before_action :set_project, only: [:show, :edit, :update, :destroy]    respond_to :html    def index     @projects = project.all     respond_with(@projects)   end    def show     respond_with(@project)   end    def new     @project = project.new     @project.pictures.build     @project.teams.build     respond_with(@project)   end     def edit   @project = project.find(params[:id])   @project.pictures.build   @project.teams.build   end    def create      @project = project.new(project_params)     if @project.save     flash[:notice] = "successfully created project."     redirect_to @project     else     render :action => 'new'     end    end    def update     @project.update(project_params)     respond_with(@project)   end    def destroy     @project.destroy     respond_with(@project)   end    private     def set_project       @project = project.find(params[:id])     end      def project_params       params.require(:project).permit(:id, :title, :description, :status, :phase, :location, :image, pictures_attributes: [:id, :image], teams_attributes: [:project_id, :user_id])     end end 


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -