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

相关问答

更多

ApplicationBar WP7(ApplicationBar WP7)

Pu it this.ApplicationBar.IsVisible = true; 在_worker.RunWorkerCompleted事件处理程序中,而不是Loaded事件 Pu it this.ApplicationBar.IsVisible = true; inside _worker.RunWorkerCompleted event handler instead of Loaded event

在WP7代码中检测DesignTime(Detect DesignTime in WP7 code)

尝试使用DesignerProperties.IsInDesignTool布尔属性。 你将需要导入System.ComponentModel命名空间来使用它。 Try using the DesignerProperties.IsInDesignTool boolean property. You will need to import the System.ComponentModel namespace to use this.

如何检测WP7原生分辨率?(How to detect WP7 native resolution?)

这是它应该做的方式: ScreenWidth = System.Windows.Application.Current.Host.Content.ActualWidth; ScreenHeight = System.Windows.Application.Current.Host.Content.ActualHeight; 您可以使用页面的“ Orientation属性将PhoneApplicationPage的默认Orientation设置为“ Portrait ”,但不能以除旋转设备本身之...

在WP7中处理双向导航?(Handling two way navigation in WP7?)

最简单的方法是通过使其成为位于Content.xaml页面顶部的全屏UserControl来完全避免瞬态加载/启动页面。 加载完成后,只需在UserControl上设置Visibility = Collapsed,即可在您的内容页面上进行操作。 现在当用户按下时,您的应用按预期退出。 这种方法在您的应用程序被Tombstone化时也很有用。 The easiest approach here is to avoid the transient loading/splash page altoget...

在wp7中线程休眠后导航到另一个页面(navigate to another page after Thread sleep in wp7)

如果您从用户控件导航,则需要获取PhoneApplicationFrame。 var myPage = Application.Current.RootVisual as PhoneApplicationFrame; myPage.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 但是,我不认为这是执行启动画面的最佳方式。 出于多种原因,尤其是在你等待时它实际上没有做任何有用的事情。 对于基本的启动画面,您将图像覆盖在MainP...

如何通过ThreadId检测线程的结束?(How do you to detect the end of a thread via ThreadId?)

不幸的是,Java中的线程没有内置这样的功能。 此外,线程id只保证在任何时候都是唯一的,但最终可以在线程死亡时(从文档中)重用。 但是,您正在使用的servlet框架可能正在实现此类功能(仅仅是一种推测)。 我建议你实现一个servlet过滤器,并告诉你的用户将它包含在他们的web.xml 。 有了这个,您可以确保客户端代码始终在您的线程上下文中正确包装。 unfortunatelly, there is no such feature built in for threads in Java....

如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)

我认为你不能处理这种情况。 我不知道你的游戏是什么,但最简单的解决方案是在ForceSave结束时或在显示另一个菜单之前调用ForceSave (我认为这是一种保存方法),只有在关闭之前你才能保存用户的进度。应用。 有时候游戏可能会毫无理由地崩溃,你必须防止这种情况发生。 简而言之,您必须修改保存逻辑。 I don't think that you can handle that case. I don't know what is your game about, but the easiest...

WP7检测线程(WP7 detect thread)

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

检测线程何时关闭(Detecting when thread has been closed)

您可以使用第一个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.Abo...

如何检测WP7手机是否正在漫游(How to detect if WP7 phone is roaming)

使用NetworkInterfaceInfo.Characteristics属性确定手机是否正在漫游。 Use the NetworkInterfaceInfo.Characteristics property to determine whether the phone is roaming.

相关文章

更多

Stack Overflow Architecture Update - Now At 95 Million Page Views A Month

A lot has happened since my first article on theSta ...

Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years

这篇文件写的非常好,推荐大家重温一下: http://highscalability.com/blog ...

Rails 风格指导

感谢译者。 本页用于介绍 Ruby 社区首推的Rails代码编写风格,翻译来自:https://git ...

Securing Solr on Tomcat access using a user account

Open [Tomcat install dir]\tomcat-users.xmlfor editi ...

USER AND SCHEMA

官方文档里面说得比较明白,schema是数据对象的集合,包括像表、视图、索引、同义词等等都可以说是sc ...

user and schema(转)

“Aschemaisacollectionofdatabaseobjects.Aschemaisown ...

配置sunspot tomcat结合sunspot_rails

1,sudo apt-get install openjdk-6-jdk 2,sudo apt-get ...

《Getting Started with Storm》译文 Homepage

拿到这本书感觉还挺薄,所以当下就想赶紧读完,然后尝试着翻译下,并加上一些自己的理解,作学习交流之用,非 ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Rails常用插件

测试驱动 rspec-rails:BDD测试框架 初始化:rails generate ...

最新问答

更多

如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)

请尝试以下方法: $messages = $user->contact_messages()->paginate(10); Try the following: $messages = $user->contact_messages()->paginate(10);

linux的常用命令干什么用的

linux和win7不一样,win7都图形界面,都是用鼠标来操作打开,解压,或者关闭。而linux是没有图形界面的,就和命令提示符一样的一个文本框,操作linux里的文件可没有鼠标给你用,打开文件夹或者解压文件之类的操作都要通过linux常用命令。

由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)

它创建了这些视图: 'auth/login.blade.php', 'auth/register.blade.php', 'auth/passwords/email.blade.php', 'auth/passwords/reset.blade.php', 'layouts/app.blade.php', 'home.blade.php' 并修改这些文件: 'Http/Controllers/HomeController.php', 'routes/web.php' 如果使用--views

如何交换返回集中的行?(How to swap rows in a return set?)

您可以使用特殊的CASE表达式进行ORDER BY如下所示: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END You can ORDER BY using a special CASE expression like this: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END

在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)

我建议你制作一个新的TableView Cell,在这个newTableViewCell中,加载第2节中的所有单元格,然后为newTableViewCell提供边框。 但如果您不想这样做,那么您可以使用以下代码: @property(strong,nonatomic) CAShapeLayer* borderPath; -(void)viewDidLayoutSubviews{ [_borderPath removeFromSuperlayer]; UIView *viewToGiveBord

使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)

出于一些奇怪的原因,我现在发现了一个不同的问题, Boost.Spirit SQL语法/词法分析失败 ,其中提供了一些其他解决方案来进行空格跳过。 一个更好的! 以下是根据建议重新编写的示例代码: #include #include #include #include #include #incl

Java中的不可变类(Immutable class in Java)

1.如果我只有final变量的课程? 这会让你远离但不是全部。 这些变量的类型也需要是不可变的。 考虑一下 class MyImmutableClass { // final variable, referring to a mutable type final String[] arr = { "hello" }; // ... } 这允许有人做 myImmutableObject.arr[0] = "world"; 并有效地改变你的不可变类的对象。 此外,建议禁

WordPress发布查询(WordPress post query)

如果你想要在div中包含所有帖子: post_parent) { $myposts = get_posts('numberposts=10&tag=medical&order=DESC'); echo ' '; foreach ($myposts as $post): ?>

如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)

我不确定哪个是MySQL的正确答案,因为它本身还不支持IPv6地址格式(尽管“ WL#798:MySQL IPv6支持 ”表明它将在MySQL v6.0中,当前文档不支持)。 不过,你建议的人建议去2 * BIGINT,但要确保他们是UNSIGNED。 在IPv6的/ 64地址边界处有一种自然分割(因为/ 64是最小的网格块大小),这将与其很好地对齐。 I'm not sure which is the right answer for MySQL given that it doesn't y

是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)

您可以使用Object.keys和Array#find来获取匹配value的key 。 const letters = {a:'26',b:'25',c:'24',d:'23',e:'22',f:'21',g:'20',h:'19',i:'18',j:'17',k:'16',l:'15',m:'14',n:'13',o:'12',p:'11',q:'10',r:'9',s:'8',t:'7',u:'6',v:'5',w:'4',x:'3',y:'2',z:'1'}; function sw