1
我試圖從Michael Hartl的Ruby on Rails教程的第12章實現以下功能,但是我是新來的Rails,我擔心我已經關閉超過我可以咀嚼。從railstutorial.org的第12章自定義以下功能的問題
我的應用程序使用設計,幷包含帖子,回覆和評論,而不是本教程前面幾章的微博。我希望能夠在遵循用戶時看到用戶的帖子,回覆和評論。
就像它現在看來的那樣,通過簡單的黑客手段,視圖都是按順序排列的,應用程序不會拋出任何可見的錯誤。
後續按鈕沒有工作,雖然,我發現了以下錯誤在終端:
NameError (undefined local variable or method `authenticate' for #<RelationshipsController:0x000001049ee238>):
應該怎麼做,以便在第12章中提供的代碼是什麼修改,把它與我的工作應用程序嗎?非常感激任何的幫助!
編輯:
這裏是我的關係控制器的代碼:
class RelationshipsController < ApplicationController
before_filter :authenticate
def create
@user = User.find(params[:relationship][:followed_id])
current_user.follow!(@user)
respond_to do |format|
format.html { redirect_to @user }
format.js
end
end
def destroy
@user = Relationship.find(params[:id]).followed
current_user.unfollow!(@user)
respond_to do |format|
format.html { redirect_to @user }
format.js
end
end
end
你可以粘貼你的RelationshipsController的代碼嗎? – JCorcuera 2011-05-27 15:55:08
Cheers @JCorcuera - 我編輯了我的原始問題以包含代碼。 – Ribena 2011-05-28 09:46:40
我已將':authenticate'更改爲':authenticate_user!'現在添加追隨者似乎有點工作,雖然我沒有從應用程序得到任何反饋,如'現在下面的用戶'。如果我點擊'關注'按鈕不會更改爲'取消關注',除非我離開頁面並返回。 – Ribena 2011-05-28 12:32:43