Привет. Я читал учебное пособие по Rails, создавая пользователей и сообщения, а также фид для их отображения.Тем не менее, автор никогда не использовал вложенные ресурсы, которые кажутся очень важными в рельсах, и я хотел бы узнать, как их использовать сам.Однако, когда я вкладываю почтовый ресурс в соответствии с Ruby в руководства по рельсам, он впоследствии ломает все мои формы и пути.
Вместо того, чтобы начинать сначала, я хотел бы перейти на вложенные ресурсы и в процессе узнать точно, в чем различия.Может кто-нибудь помочь с тем, как я поступил бы по этому поводу?Спасибо за любую помощь.
Особенно я озадачен тем, как поступить с кормом.В настоящее время feed_item вызывает старый post_path.
shared / _feed_item частичный
<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>
контроллер микросообщений
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
Это запускается в разделе 11.3.3 этой главы http://ruby.railstutorial.org/chapters/user-microposts#top и построено для реальных в 12.3 этой главы http://ruby.railstutorial.org/chapters/following-users#top