【问题标题】:Ruby on Rails & FullCalendar: Is there any way to add a link to the title header?Ruby on Rails 和 FullCalendar:有没有办法在标题标题中添加链接?
【发布时间】:2015-07-14 05:19:00
【问题描述】:

我的简单应用程序中有一个页面,它显示带有 jQ​​uery 插件 http://fullcalendar.io/ 的日历。

我想为标题添加一个链接,以便用户在其他地方导航到不同的视图。这可能吗?日历本身的文档很差。具体来说,我想添加一个 FontAwesome 图标并让它在点击时重定向用户。

我知道自定义标题非常简单——只需像这样指定自定义标题:

<div id="calendar"></div>

<script>
  $('#calendar').fullCalendar({
    header: {
      left: 'prevYear,nextYear',
      center: 'title',           
    },
    titleFormat: '[Hello, World!]'
  });
</script>

但是,我正在尝试使用 Rails 助手 link_to 在日历旁边添加一个链接。这可能吗?这是我的尝试,但它不起作用:

<div id="calendar"></div>

<script>
  $('#calendar').fullCalendar({
    header: {
      left: 'prevYear,nextYear',
      center: 'title',
    },
    titleFormat: '[<%= link_to '<i class="fa fa-icon"></i>'.html_safe, some_path %>']'
  });
</script>

【问题讨论】:

    标签: ruby-on-rails ruby calendar fullcalendar erb


    【解决方案1】:

    您在这一行有错字:

        titleFormat: '[<%= link_to '<i class="fa fa-icon"></i>'.html_safe, some_path %>']'
    

    %&gt; 后面多了一个单引号。试试这个:

        titleFormat: '[<%= link_to '<i class="fa fa-icon"></i>'.html_safe, some_path %>]'
    

    如果修复后仍有问题,请尝试查看 FullCalendar 的 titleFormat 属性支持的内容。我不知道 FullCalendar 是否试图允许您将任意 HTML 放入该属性中——that property’s docs 并不清楚。您可以查看FullCalendar’s documentation 的其余部分或其source code that handles that property

    您对link_tohtml_safe 的使用对我来说看起来不错。

    【讨论】:

    • 似乎不支持 html...不过感谢您的编辑和帮助我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 2021-06-09
    • 1970-01-01
    • 2020-04-05
    • 2023-03-07
    相关资源
    最近更新 更多