【问题标题】:Ruby on Rails link issueRuby on Rails 链接问题
【发布时间】:2011-12-11 15:06:32
【问题描述】:

我的代码中有这种语法,但显示方式不同:

<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>

浏览器中的结果:

(Ruby on Rails Tutorial(http://railstutorial.org

谁能告诉我怎么了?我有一个 Rails 3.1.3 版本和一个 ruby​​ 1.9.2p0 版本。

【问题讨论】:

  • 示例应用

    railstutorial.org/">Ruby on Rails 教程

  • 可以显示代码的周边区域吗?
  • Sample App

    Ruby on Rails 教程

    //这是所有代码在页面中。该页面在视图文件中
  • 把“http://”放在“railstutorial.org”之前
  • 让我们退后一步:您的控制器中用于此方法的内容是什么?你能把所有东西都放在def和end之间吗?

标签: ruby-on-rails


【解决方案1】:

我遇到了同样的问题,通过更正我的样式表链接以及更好地理解资产管道来解决它。我因旧版 Rails 教程而包含的 Blueprint css 文件夹是问题的根源。我允许 rails 将这些文件夹中的某些内容错误地编译到我的 app/assets/stylesheets/application.css 文件中,而没有将 :media 定义为屏幕或打印。

我通过编写自己的 css 文件解决了这个问题,将它们包含在与 app/assets/stylesheets/application.css 相同的文件夹中,添加 .scss 扩展名 (style.css.scss) (rails 3.1.3) 链接只删除到“应用程序”文件,并从我的 app/assets/stylesheets/ 文件夹中完全删除 Blueprint css 库文件夹,它本来不应该放在首位。

   #  For rails 3.0 and up, delete blueprint folder and
   #  put any custom css files you want in the app/assets/stylesheets folder by 
   #  themselves, adding the .scss extension.They should automatically be loaded into 
   #  application.css through  the assets pipeline.
   #  In your stylesheets helper layout file, or application layout file,
   #  (where ever you keep your stylesheet linking), only link to:

   stylesheet_link_tag "application"

或者,如果您没有使用 3.0 或更高版本,并且没有处理资产管道,则可以通过定义您链接到的样式表的媒体类型来解决该问题:

   stylesheet_link_tag "blueprint/screen", :media => "screen"

另一个帖子提到了这个问题:

Similar Problem...

【讨论】:

    【解决方案2】:

    Try using the "link_to" method in RoR:

    link_to(body, url, html_options = {})
    

    link_to("Ruby on Rails Tutorial", "http://railstutorial.org")
    

    link_to "Ruby on Rails Tutorial", "http://railstutorial.org" 
    

    【讨论】:

    • 这句话之前有问题。我怀疑你没有正确地逃避 ruby​​ 或关闭语句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多