ruby on rails - How to show confirmed invintations in RoR? -
this question exact duplicate of:
- why error no such column? 1 answer
i have model invintation, , model company, company can send messages each other after confirmation of invitation messaging.
invintation.rb
class invintation < activerecord::base belongs_to :recipient, class_name: 'company', foreign_key: 'recipient_id' belongs_to :sender, class_name: 'company', foreign_key: 'sender_id' belongs_to :author, class_name: 'user', foreign_key: 'author_id' end
company.rb
class company < activerecord::base has_many :users_companies has_many :users, through: :users_companies has_many :sent_messages, class_name: 'message', foreign_key: 'sender_id' has_many :incoming_messages, class_name: 'message', foreign_key: 'recipient_id' has_many :sent_invitations, class_name: 'invintation', foreign_key: 'sender_id' has_many :invitation_recipients, through: :sent_invitations, source: :recipient has_many :incoming_invitations, class_name: 'invintation', foreign_key: 'recipient_id' has_many :invitation_senders, through: :incoming_invitations, source: :sender end
on form want show companies confirmed invitation
<%= form_for([@company, @message]) |f| %> <%= f.text_field :subject, placeholder: "тема" %> <%= f.collection_select :category_id, category.all, :id, :name, class: "form-control" %> <%= f.collection_select :recipient_id, @recipients, :id, :name, class: "form-control" %> <%= f.submit %> <% end %>
so add controller code
class messagescontroller < applicationcontroller def new @company = company.find(params[:company_id]) @message = @company.sent_messages.new @recipients = @company.invitation_recipients.where(confirm: true) end def create @company = company.find(params[:company_id]) @message = @company.messages.build(mess_params) @message.author_id = current_user @message.sender_id = @company.id if @message.save flash[:success] = "Документы успешно отправлены" redirect_to inbox_path(@company) end end end
but dont know how can show in @recipients confirmed companies, did go wrong?
i not sure if efficient way have model invitations , model linked companies. when company invites company invitation created. when other company accepts invitation destroyed , link between companies created. show companies option receive messages linked companies.
Comments
Post a Comment