up vote
down votefavorite 
<http://stackoverflow.com/questions/35296344/add-properties-to-a-list-rails4#>

Property has many lists. List has many properties. Users can add properties 
to a list , here user must be owner of those properties which he want to 
add.

Here is my code:

class List < ActiveRecord::Base
  has_many :propertyships
  has_many :properties, :through => :propertyshipsend
class Propertyship < ActiveRecord::Base
  belongs_to :list
  belongs_to :propertyend
class Property < ActiveRecord::Base
  has_many :propertyships
  has_many :lists, :through => :propertyshipsend

in view:

<%= simple_form_for(@list, url: add_property_list_path,  :method => :put) do 
|f| %>
   <%= f.collection_check_boxes(:property_ids, @user_all_properties, :id, 
:street_address) %>
   <%= f.submit "Add Property" %><% end %>

in routes:

  resources :lists do
    member do
      put 'add_property'
    end
  end

in controller:

  def add_property
    @list = List.find(params[:id])
    @list.update_attributes(list_params)
  end
  private
  def list_params
    params.require(:list).permit(:name, :user_id, property_ids: [])
  end

when I checked properties and I click "Add property" button as other user , 
its add checked properties but remove old properties that I have in that 
particular list. what a I doing wrong??

-- 
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/024e7691-f1b3-457f-9794-852cd1a36c78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to