2012-01-16 117 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