ruby - How to get 'feed' method in User model not private so I can show feeds in my static_page/home page (Michael Hartl Rails Tutorial) -
I am following the rail tutorial of Michael Hartl and I am in Chapter 10.36 where The user will be shown on the home page I should be able to see all the posts on the home page, but should I keep getting when I get to section 10.41 in a
StaticPagesController # home private method called `feed '# & lt NoMethodError; User: 0x007f881cf77410 & gt; If signed_in? @micropost = current_user.microposts.bild if signed_in? @feed_items = current_user.feed.paginate (page: parameter [: pg]) & lt; - Error line end end How do I get User.feed method can not use private in this happening home page?
Code for user.rb
class user & lt; Verify: name, presence: true, length: {max: 50} VALID_EMAIL_REGEX = / \ a [\ w + \ -.] + @ [Az \ d \ -] + (?: \. [Az \ d \ -] +) * \. [Az] + \ z / i Valid: Email, Attendance: Correct, Format: {with: VALID_EMAIL_REGEX}, Specification: {case_ Sensitive: False} has_secure_password is valid: Password, Length: {Minimum: 6} End Diff Feed # For the initial complete implementation see "The following users": Micropost.where ("user_id =?", Id) end DEF User.new_remember_token SecureRandom.urlsafe_base64 End User.digest Def (token) digest :: SHA1.hexdigest (token.to_s) Def private end create_remember_token self.remember_token = User.digest (User.new_remember_token) end for static_page controller E
class StaticPagesController & lt; Signature_in ApplicationController def home? @micropost = current_user.microposts.bild if signed_in? @feed_items = current_user.feed.paginate (page: parameter [: pages]) End end DEF end DEF contact end end about DEF help home page view code
& lt;% if signed? & Gt%; & Lt; Div class = "row" & gt; & Lt; Separate class = "span4" & gt; & Lt; Section & gt; & Lt;% = Render 'shared / user_info'% & gt; & Lt; / Section & gt; & Lt; Section & gt; & Lt;% = Render 'shared / microprost_arm'% & gt; & Lt; / Section & gt; & Lt; / One side & gt; & Lt; Div class = "span8" & gt; & Lt; H3 & gt; Post feed & lt; / H3 & gt; & Lt;% = Render 'Shared / Feed'% ' & Lt; / Div & gt; & Lt; / Div & gt; 'share / feed' file
<% if @ feed_item.any%> & Lt; Ol class = "microprost" & gt; & Lt;% = Partial Render: 'Shared / Feed_ITOM', Archive: @ Feed_Intems% & gt; & Lt; / Ol & gt; & Lt;% = will_paginate @ feed_items% & gt; & Lt;% end% & gt;
According to the error, for the private method feed ' # `, You are calling on the example of the private name feed name of the user model. To work out the code
@feed_items = current_user.feed.paginate (Page: Parameters [: Page]) Make sure the method is not under the feed in the user model private section. Just remember, a personal method (i.e. the method declared outside of any class) can not be called on other objects.
UPDATE User> class, defaults before defined methods Class user & lt; ActiveRecord :: Base ## ... Verifies: Password, Length: {Minimum: 6} End ## Remove This End Def Feed ## ... create_remember_token self.remember_token = User.digest (User.new_remember_token) End end Def personal ## Add this closing
Comments
Post a Comment