i have three tables, RM, GenericUser and Properties.
RM fields :id, name
generic_users fields are: id,mobile,rm_id,name.
Properties fields are: id,image,rm_id,generic_user_id,property_name.
RM is creating GenericUsers,so that rm_id automatically entered in Generic Users table.
After that generic user logs in and creates property,so when generic user creates property,rm_id should fetch from generic user table and should enter in property table field where rm_id is there.
i have model relation like this.
class Rm < ActiveRecord::Base acts_as :user has_many :generic_users end
class Property < ActiveRecord::Base belongs_to :generic_user end
class GenericUser < ActiveRecord::Base belongs_to :rm has_many :properties end
my generic_users propertiescontroller
def create @property = Property.new(property_params) @gu=GenericUser.select(:rm_id).where(:id=>current_user.specific.id) @property.rm_id=@gu.rm_id logger.info @property.rm_id.inspect if @property.save redirect_to :back, notice: 'Property was successfully created.' else render :new end end
Please help if any idea. Any help is appreciatable
Aucun commentaire:
Enregistrer un commentaire