Rails - 显示用户在上个月开始关注的用户(Rails - Show the users that a user started following in the last month)
对这个问题道歉,我还在学习铁轨。 我试图在我的HTML中显示 - 用户在上个月内开始关注的所有用户(即您已关注的最近用户)。 我尝试了两种方法 - 都不成功。 我的第一次尝试是在我的控制器中,但我得到的最接近的是显示用户我已经开始关注上个月创建的用户。 我的第二次尝试是在我的用户模型中 - 但我得到未定义的方法`call'for#你的意思是? 呼叫者
following.html.erb
<div class="tab-content"> <div id="fire" class="tab-pane fade"> <% @followingurecent.each do |recentfollowing| %> <div class="box"> <center> <%= image_tag recentfollowing.avatar, width: 85 %> </center> </div> <% end %> </div> </div>
Users_controller.rb
def following @user = User.find(params[:id]) now = Time.now @followingurecent = @user.following.where(created_at: (now - 1.month)..Time.now) end
User.rb
has_many :active_relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy has_many :passive_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy has_many :following, through: :active_relationships, source: :followed has_many :followers, through: :passive_relationships, source: :follower def follow(other) active_relationships.create(followed_id: other.id) Notification.create(recipient: @user, actor: User.current_user, action: "Followed", notifiable: @user) end def unfollow(other) active_relationships.find_by(followed_id: other.id).destroy end def following?(other) following.include?(other) end def followingrecent now = Time.now self.following.where(active_relationships.where.(created_at: (now - 1.day)..Time.now)) end
Apologies for the question, I'm still learning rails. I'm trying to show in my html - all the users that a user has started following within the last month (i.e. recent users you've followed). I've tried two approaches-both unsuccessful. My first try was in my controller but the closest I got was showing users I've started following who were created in the last month. My second try was in my user model - but I get undefined method `call' for # Did you mean? caller
following.html.erb
<div class="tab-content"> <div id="fire" class="tab-pane fade"> <% @followingurecent.each do |recentfollowing| %> <div class="box"> <center> <%= image_tag recentfollowing.avatar, width: 85 %> </center> </div> <% end %> </div> </div>
Users_controller.rb
def following @user = User.find(params[:id]) now = Time.now @followingurecent = @user.following.where(created_at: (now - 1.month)..Time.now) end
User.rb
has_many :active_relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy has_many :passive_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy has_many :following, through: :active_relationships, source: :followed has_many :followers, through: :passive_relationships, source: :follower def follow(other) active_relationships.create(followed_id: other.id) Notification.create(recipient: @user, actor: User.current_user, action: "Followed", notifiable: @user) end def unfollow(other) active_relationships.find_by(followed_id: other.id).destroy end def following?(other) following.include?(other) end def followingrecent now = Time.now self.following.where(active_relationships.where.(created_at: (now - 1.day)..Time.now)) end
原文:https://stackoverflow.com/questions/43029961
满意答案
我认为
System.Threading.Thread.CurrentThread
在WP7上可用。 您可以使用它来识别您所在的线程。检查这里的文档: Thread.CurrentThread
I think that
System.Threading.Thread.CurrentThread
is available on WP7. You can use this to identify which thread you are on.Check the docs here: Thread.CurrentThread
相关问答
更多ApplicationBar WP7(ApplicationBar WP7)
在WP7代码中检测DesignTime(Detect DesignTime in WP7 code)
如何检测WP7原生分辨率?(How to detect WP7 native resolution?)
在WP7中处理双向导航?(Handling two way navigation in WP7?)
在wp7中线程休眠后导航到另一个页面(navigate to another page after Thread sleep in wp7)
如何通过ThreadId检测线程的结束?(How do you to detect the end of a thread via ThreadId?)
如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)
WP7检测线程(WP7 detect thread)
检测线程何时关闭(Detecting when thread has been closed)
如何检测WP7手机是否正在漫游(How to detect if WP7 phone is roaming)
相关文章
更多Stack Overflow Architecture Update - Now At 95 Million Page Views A Month
Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years
Rails 风格指导
Securing Solr on Tomcat access using a user account
USER AND SCHEMA
user and schema(转)
配置sunspot tomcat结合sunspot_rails
《Getting Started with Storm》译文 Homepage
Becoming a data scientist
Rails常用插件
最新问答
更多如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
linux的常用命令干什么用的
由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
如何交换返回集中的行?(How to swap rows in a return set?)
在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
Java中的不可变类(Immutable class in Java)
WordPress发布查询(WordPress post query)
如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!