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)[2022-12-13]
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 ...
-
如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)[2022-01-30]
我认为你不能处理这种情况。 我不知道你的游戏是什么,但最简单的解决方案是在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 ... -
WP7检测线程(WP7 detect thread)[2022-04-16]
我认为 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 ... -
检测线程何时关闭(Detecting when thread has been closed)[2023-06-02]
您可以使用第一个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.