首页 \ 问答 \ Rails - 显示用户在上个月开始关注的用户(Rails - Show the users that a user started following in the last month)

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
更新时间:2024-03-26 21:03

最满意答案

认为 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

相关问答

更多
  • Pu it this.ApplicationBar.IsVisible = true; 在_worker.RunWorkerCompleted事件处理程序中,而不是Loaded事件 Pu it this.ApplicationBar.IsVisible = true; inside _worker.RunWorkerCompleted event handler instead of Loaded event
  • 尝试使用DesignerProperties.IsInDesignTool布尔属性。 你将需要导入System.ComponentModel命名空间来使用它。 Try using the DesignerProperties.IsInDesignTool boolean property. You will need to import the System.ComponentModel namespace to use this.
  • 这是它应该做的方式: ScreenWidth = System.Windows.Application.Current.Host.Content.ActualWidth; ScreenHeight = System.Windows.Application.Current.Host.Content.ActualHeight; 您可以使用页面的“ Orientation属性将PhoneApplicationPage的默认Orientation设置为“ Portrait ”,但不能以除旋转设备本身之外的任何其 ...
  • 最简单的方法是通过使其成为位于Content.xaml页面顶部的全屏UserControl来完全避免瞬态加载/启动页面。 加载完成后,只需在UserControl上设置Visibility = Collapsed,即可在您的内容页面上进行操作。 现在当用户按下时,您的应用按预期退出。 这种方法在您的应用程序被Tombstone化时也很有用。 The easiest approach here is to avoid the transient loading/splash page altogether, ...
  • 如果您从用户控件导航,则需要获取PhoneApplicationFrame。 var myPage = Application.Current.RootVisual as PhoneApplicationFrame; myPage.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 但是,我不认为这是执行启动画面的最佳方式。 出于多种原因,尤其是在你等待时它实际上没有做任何有用的事情。 对于基本的启动画面,您将图像覆盖在MainPage.x ...
  • 不幸的是,Java中的线程没有内置这样的功能。 此外,线程id只保证在任何时候都是唯一的,但最终可以在线程死亡时(从文档中)重用。 但是,您正在使用的servlet框架可能正在实现此类功能(仅仅是一种推测)。 我建议你实现一个servlet过滤器,并告诉你的用户将它包含在他们的web.xml 。 有了这个,您可以确保客户端代码始终在您的线程上下文中正确包装。 unfortunatelly, there is no such feature built in for threads in Java. Besi ...
  • 我认为你不能处理这种情况。 我不知道你的游戏是什么,但最简单的解决方案是在ForceSave结束时或在显示另一个菜单之前调用ForceSave (我认为这是一种保存方法),只有在关闭之前你才能保存用户的进度。应用。 有时候游戏可能会毫无理由地崩溃,你必须防止这种情况发生。 简而言之,您必须修改保存逻辑。 I don't think that you can handle that case. I don't know what is your game about, but the easiest solu ...
  • 我认为 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.Curre ...
  • 您可以使用第一个Window中的Window_Closed事件: private void Window1_Closed(object sender, EventArgs e) { Window2.Close(); // Close your second window } 然后在第二个窗口中: private void Window2_Closed(object sender, EventArgs e) { // abort all Threads thread.Abort(); ...
  • 使用NetworkInterfaceInfo.Characteristics属性确定手机是否正在漫游。 Use the NetworkInterfaceInfo.Characteristics property to determine whether the phone is roaming.

相关文章

更多

最新问答

更多
  • Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)
  • C ++ 11 + SDL2 + Windows:多线程程序在任何输入事件后挂起(C++11 + SDL2 + Windows: Multithreaded program hangs after any input event)
  • AccessViolationException未处理[VB.Net] [Emgucv](AccessViolationException was unhandled [VB.Net] [Emgucv])
  • 计算时间和日期差异(Calculating Time and Date difference)
  • 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
  • C#对象和代码示例(C# objects and code examples)
  • 在python中是否有数学nCr函数?(Is there a math nCr function in python? [duplicate])
  • 检索R中列的最大值和第二个最大值的行名(Retrieve row names of maximum and second maximum values of a column in R)
  • 给定md5哈希时如何查找特定文件(How to find specific file when given md5 Hash)
  • Python字典因某些原因引发KeyError(Python Dictionary Throwing KeyError for Some Reason)
  • 如何让Joomla停止打开新标签中的每个链接?(How do I get Joomla to stop opening every link in a new tab?)
  • DNS服务器上的NS记录不匹配(Mismatched NS records at DNS server)
  • Python屏幕捕获错误(Python screen capture error)
  • 如何在帧集上放置div叠加?(How to put a div overlay over framesets?)
  • 页面刷新后是否可以保留表单(html)内容数据?(Is it possible to retain the form(html) content data after page refreshed?)
  • 使用iTeardownMyAppFrame和iStartMyAppInAFrame在OPA5测试中重新启动应用程序超时(Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out)
  • 自动拆分文本内容到列(Automatically splitting text content into even columns)
  • 在r中的循环中将模型名称分配给gbm.step(assigning model names to gbm.step in loop in r)
  • 昆明哪里有电脑等级考试二级C培训?
  • C ++模板实例化,究竟是什么意思?(C++ template instantiation, what exactly does it mean?)
  • 帮助渲染来自fields_for的部分内容(Help to render a partial from fields_for)
  • 将url.action作为json对象返回mvc(return url.action as json object mvc)
  • 使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
  • 将bindingRedirect添加到.Net标准库(Adding a bindingRedirect to a .Net Standard library)
  • Laravel版本升级会影响您的控制器吗?(Laravel version upgrade affects your controller?)
  • imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
  • 如何在eclipse debug impala前端
  • 如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])
  • 使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)
  • JS 实现一个菜单效果