Tag: railscasts

如何使用私人提交来隐藏Feed?

在评估表单中,有一个提交按钮和一个按钮。 如果单击私人提交,则提交的信息将隐藏给查看该个人资料的其他用户。 我们如何使用来隐藏提交的信息以显示在Feed上? 活动/ index.html.erb Feed #We’d need to make .public_valuations work with this without getting an undefined method error. activities_controller.rb class ActivitiesController < ApplicationController def index @activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.following_ids, owner_type: "User") end end 为简洁起见,我只会包含_create (还有update和destroy )。 每次用户提交评估时,它都会在Feed上弹出,我们怎样才能显示public_valuations ? public_activity /评估/ _create.html.erb which has since been removed valuation.rb class Valuation (controller, model) { […]

与Faye和Rails的私人消息

我正在使用在railscast中播放的faye gem ,允许应用程序推送消息。 问题是它将消息推送到所有打开的聊天客户端。 我需要他们是私人的。 可以通过faye获取私人消息,但它是基于url的。 例如,所有消息都将发送到site.com/foo 。 但是,在我的模型中,聊天没有特定的url。 因为聊天只是该用户发送给您的邮件集合。 因此,如果您以adam site.com/messages/eve身份登录,那么您可以与前夕交谈,但前夕则相反。 site.com/messages/adam 。 因此,特定于URL的私人聊天似乎是不可能的。 有什么指针吗? messages_controller.rb (触发ajax) def create @message = Message.new(message_params) @message.save end create.js.erb (调用广播方法) $(“.text-wrap”).append(” “); 广播方法 (发布到王菲服务器) def broadcast(user, &block) channel = “/messages/#{user}” message = {:channel => channel, :data => capture(&block)} uri = URI.parse(“http://localhost:9292/faye”) Net::HTTP.post_form(uri, :message => message.to_json) end application.js (faye服务器订阅/ […]

Ruby map方法语法问题

可能重复: map(&:name)在Ruby中意味着什么? 我正在观看railscasts更多的虚拟属性剧集 。 在那一集中,有一次,ryan使用了我无法理解的地图方法语法,有人可以解释一下吗? tags.map(&:name).join(‘ ‘) tags是Tag Model的一个对象,它具有name属性。 我能够理解这个的含义(我想是:))。 所有标记对象的name属性都作为数组检索并基于”连接。 但与&:name的交易是什么 谢谢