English 中文(简体)
Railwaystutorial.org书,改道
原标题:Railstutorial.org book, changing to nested routes

此前,我一直在铁路图西里书上跟踪,创建用户和职位,并提供一个显示职位的信息。 然而,提交人从未使用过专用资源,这似乎在铁路中非常重要,我要发现如何使用这些资源。 然而,当我根据Ruby在铁路指南中提供员额资源时,它随后打破了我的所有形式和道路。

Instead of starting over I would like change over to nested resources and in the process learn exactly what the differences are. Can anyone help with how I would go about this? Thanks for any help.

尤其是 我对如何使用饲料感到迷惑。 目前,供款——项目指旧员额。

shared/_feed_item partial

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

micropost controller

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” rel=“nofollow” http://ruby.railstutorial.org/ Chapters/user-microposts#top。 http://ruby.railstutorial.org/ Chapters/following-users#top” rel=“nofollow” http://ruby.railstutorial.org/ Chapters/following-users#top

最佳回答

这里有一些联系将启动:

railscasts.com/episodes/139-nested-resources
railscasts.com/episodes/196-nested-model-form-part-1
railscasts.com/episodes/197-nested-model-form-part-2

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签