【问题标题】:render a template with link_to rails 3.1使用 link_to rails 3.1 渲染模板
【发布时间】:2012-02-11 09:48:23
【问题描述】:

我正在尝试通过单击链接来呈现模板。

这是我正在做的事情:-

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

这给了我一个错误:-

设置中的语法错误#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

这是错误:-

语法错误,意外的 tSYMBEG,在这一行需要关键字_do 或 '{' 或 '(' %li=link_to"profile", 渲染 :template => "profile"

这是生成的错误标记:-

语法错误,意外的 tSYMBEG,需要关键字_do 或 '{' 或 '(' ...se((link_to("profile", render :template => “个人资料”

可能是什么问题?

【问题讨论】:

  • 是什么偏方?显示它。
  • @SergioTulentsev 更新了错误
  • 你想在不重新加载页面的情况下这样做吗?
  • @SergioTulentsev 我只希望页面是否重新加载无关紧要
  • 生成的标记是什么样的?

标签: ruby-on-rails ruby-on-rails-3.1


【解决方案1】:

你做错了。

= link_to 'Profile', @profile

这将产生类似于

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

单击将调用哪个 ProfilesController#show 并呈现相应的视图。

当然,您可以在此处触发 ajax 查询,获取呈现的模板并动态显示它,但我认为,现在对您来说还为时过早。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多