如何使用私人提交来隐藏供稿? [英] How to use private submit to hide from feed?
问题描述
在评估表中,有一个提交按钮和一个<%= f.submit :private %>
按钮.如果单击了私人提交,则提交的信息将对查看该个人资料的其他用户隐藏.
In the valuations form there is a submit button and a <%= f.submit :private %>
button. If private submit is clicked the submitted info will be hidden to other user's who view the profile.
我们还如何使用<%= f.submit :private %>
隐藏提交的信息以使其不在Feed上显示?
How can we also use <%= f.submit :private %>
to hide submitted info from showing on the feed?
activities/index.html.erb
<h1>Feed</h1>
<% @activities.each do |activity| %>
<% if current_user == @user %>
<%= render_activity activity %>
<% else %>
<%= render_activity activity %> #We'd need to make .public_valuations work with this without getting an undefined method error.
<% end %>
<% end %>
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上弹出该评估,我们如何仅进行
For brevity I'll only include _create
(there is also update
and destroy
). Every time a user submits a valuation it pops up on the feed, how can we make only public_valuations
show?
public_activity/valuation/_create.html.erb
<% if activity.trackable %>
<%= link_to activity.trackable.name, activity.trackable %></b>
<% else %>
which has since been removed
<% end %>
valuation.rb
class Valuation < ActiveRecord::Base
belongs_to :user
acts_as_taggable
validates :name, presence: true
has_many :comments, as: :commentable
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }
def public?
private == true ? false : true
end
scope :randomize, -> do
order('RANDOM()').
take(1)
end
end
users_controller
def show
if
@valuations = @user.valuations
else
@valuations = @user.public_valuations
end
end
user.rb
#gets public valutations or nil, if there's no public valutation
def public_valuations
valuations.find(&:public?)
end
我从以下railscasts剧集获得了几乎所有的活动代码: http://railscasts. com/episodes/406-public-activity .
I gained almost all of my activities code form this railscasts episode: http://railscasts.com/episodes/406-public-activity.
这是我们如何使个人提交个人资料的工作: 如何使用私人提交来隐藏个人资料?
This is how we made the private submit work for the profile: How to use private submit to hide from profile?
非常感谢您抽出宝贵的时间!
Thank you so much for your time!
由于我们无法通过public_activity gem解决此问题,因此我从头开始创建了公共活动,并尝试在此处解决此问题: 如何进行私人活动?
Since we couldn't resolve the issue via the public_activity gem I created the public activity from scratch and am attempting to resolve this issue here: How to make private activities?
推荐答案
失败的尝试
根据Avdept的建议:
FAILED ATTEMPT
at Avdept's suggestions:
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.not_private.order("created_at desc").where(owner_id: current_user.following_ids, owner_type: "User")
end
end
在 valuations.rb
def public? !private end => def public?; !private; end;
scope :not_private, -> { where(private: false) }
这给出了:
SyntaxError in ActivitiesController#index (for line: def public? !private end => def public?; !private; end;)
/Users/galli01anthony/Desktop/Pecoce/app/models/valuation.rb:9: syntax error, unexpected '!', expecting ';' or '\n' def public? !private end => def public?; !private; end; ^ /Users/galli01anthony/Desktop/Pecoce/app/models/valuation.rb:9: syntax error, unexpected =>, expecting end-of-input def public? !private end => def public?; !private; end; ^
这篇关于如何使用私人提交来隐藏供稿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!