【发布时间】:2015-06-07 19:35:14
【问题描述】:
我正在尝试让用户将传入好友请求的状态从“未接受”更改为“已接受”
用户模型
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :places
has_many :sent_friendships, class_name: "Friendship" , foreign_key: :sender_id
has_many :received_friendships, class_name: "Friendship", foreign_key: :receiver_id
友谊模型
class Friendship < ActiveRecord::Base
belongs_to :sender, class_name: "User"
belongs_to :receiver, class_name: "User"
end
用户显示视图
<h1>Incoming Friend Requests</h1>
<% current_user.received_friendships.each do |friendship| %>
<%= friendship.sender.name %>
<%= link_to "Accept", user_accept_path(current_user), class: 'btn btn-success', method: :post %>
<% end %>
友谊控制器
class FriendshipsController < ApplicationController
def accept
@user = User.find(params[:user_id])
end
end
我在哪里磕磕绊绊,因为我不确定如何最好地加上发送者 ID 和接收者 ID 以更新友谊模型表上的正确行。
感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails ruby