2012-01-16 114 views
0

我想通過單擊鏈接呈現模板。使用link_to rails呈現模板3.1

下面是我在做什麼: -

link_to "Profile", render :template => "profile" 

這給了我一個錯誤: -

SyntaxError in Settings#account_setting

這裏是我的設置控制器: -

class SettingsController < ApplicationController 
    before_filter :authenticate_user! 

    def profile 
     @user = current_user 
     request.method.inspect 
     if request.method == "POST" 
      @user.update_attributes(params[:user]) 
      flash[:notice] = "You updated your profile successfully." 
     end 
    end 

    def account_setting 
    end 

end 

這是錯誤: -

syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' on this line %li=link_to"profile", render :template => "profile"

這是錯誤的生成的標記: -

syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' ...se((link_to("profile", render :template => "profile"

可能是什麼問題?

+0

它是什麼樣的偏方?展示下。 – 2012-01-16 12:51:21

+0

@SergioTulentsev更新了錯誤 – 2012-01-16 12:51:40

+0

你想不要重新加載頁面嗎? – 2012-01-16 12:55:27

回答

0

你做錯了。

= link_to 'Profile', @profile 

這將產生類似

<a href="/profiles/1">Profile</a> 

一旦點擊該ProfilesController#節目將被調用,相應的視圖中呈現的東西。

當然,您可以在這裏激發一個ajax查詢,獲取呈現的模板並動態顯示它,但我認爲現在對您來說還爲時過早。

+0

謝謝你會看到如何做到這一點 – 2012-01-16 13:19:55