首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Railstutorial.org帐簿,更改为嵌套路由

Railstutorial.org帐簿,更改为嵌套路由
EN

Stack Overflow用户
提问于 2011-04-27 14:43:24
回答 1查看 228关注 0票数 0

您好,我一直在学习Rails教程中的内容,创建用户和帖子,以及显示帖子的提要。然而,作者从未使用过嵌套资源,这在rails中似乎非常重要,我想亲自了解如何使用它们。然而,当我根据Ruby on rails指南嵌套post资源时,它随后破坏了我所有的表单和路径。

我不想从头开始,而是希望更改为嵌套资源,并在此过程中准确地了解它们之间的区别。有没有人能帮我解决这个问题呢?谢谢你的帮助。

特别是我对如何处理提要感到困惑。目前,feed_item调用旧的post_path。

共享/_feed_item部分

代码语言:javascript
复制
<tr>
  <td class="avatar">
   <%= link_to avatar_for(feed_item.user), feed_item.user %>
  </td>
  <td class="post">
   <span class="title"><%= link_to feed_item.title, feed_item %></span><br />
   <span class="content">the plot: <%= feed_item.content %></span><br />
   <span class="timestamp">
   Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
   </span>
 </td>
 </td>

   <% if current_user?(feed_item.user) %>
 <td>
  <%= link_to "delete", feed_item, :method => :delete,
                                  :confirm => "You sure?",
                                  :title => feed_item.content %>
 </td>
 <% end %>
</tr>

微柱控制器

代码语言:javascript
复制
class Micropost < ActiveRecord::Base
  .
  .
  .
  default_scope :order => 'microposts.created_at DESC'

  # Return microposts from the users being followed by the given user.
 scope :from_users_followed_by, lambda { |user| followed_by(user) }

  private

    # Return an SQL condition for users followed by the given user.
    # We include the user's own id as well.
    def self.followed_by(user)
      followed_ids = %(SELECT followed_id FROM relationships
                       WHERE follower_id = :user_id)
      where("user_id IN (#{followed_ids}) OR user_id = :user_id",
            { :user_id => user })
    end
end

它在本章http://ruby.railstutorial.org/chapters/user-microposts#top的11.3.3节中开始,并在本章http://ruby.railstutorial.org/chapters/following-users#top的12.3节中针对reals构建

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-27 14:46:39

以下是一些帮助您入门的链接:

Railscasts.com/episodes/139-嵌套资源

railscasts.com/episodes/196-nested-model-form-part-1

railscasts.com/episodes/197-nested-model-form-part-2

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5800399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档