【问题标题】:How not get current_user如何获取不到 current_user
【发布时间】:2015-09-28 20:47:44
【问题描述】:

为了让用户了解这种情况,我很头疼:

对话模型:

has_many :conversation_participants, :dependent => :destroy
  has_many :users,
    :through => :conversation_participants
  has_many :messages, :dependent => :destroy
  has_one :display_message,
    :class_name => 'Message',
    :order => 'created_at DESC'

  def participants(options={})
    if options[:not].is_a? User
      users - [options[:not]]
    else
      users
    end
  end

和 conversation_participants:

belongs_to :user
belongs_to :conversation
attr_accessible :user_id

关于对话助手:

 def self_or_other
    @conversation.conversation_participants.find_by_user_id(:not => current_user)
  end

拜托,有人可以告诉我如何让其他用户进入 conversation_participants 模型?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems


    【解决方案1】:

    我相信如下:

    @conversation.conversation_participants.where.not(user_id: current_user.id).first
    

    【讨论】:

    • 非常感谢@Малъ-Скрылевъ,但在日志中显示:参数数量错误(0 表示 1+)
    • @Danielfir 哪个方法?请提供traceback的部分,以及错误地方的代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多