2015-04-28 3 views
-2

Я пытаюсь реализовать Example, но у меня возникают проблемы с самого начала. Я не вижу календарь на странице. Однако, когда я загружаю код с веб-страницы и делаю это, он работает.Rails Полный календарь не может быть показан

Так что я сделал это

  1. создать демонстрационную папку (рельсы нового демо)
  2. генерировать подмости (рельсы г эшафот название события: строковое описание: текст start_time: DATETIME END_TIME: DateTime)
  3. грабли БД: мигрировать
  4. Затем я добавил gem 'fullcalendar-rails'
  5. пакет установки
  6. добавил JS и CSS
  7. добавил JS инициировать каландра
  8. положить Div тег в index.html.erb

Так до сих пор я не могу увидеть календарь.

Адрес: gem file;

source 'https://rubygems.org' 

gem 'rails', '4.2.1' 
gem 'sqlite3' 
gem 'sass-rails', '~> 5.0' 
gem 'uglifier', '>= 1.3.0' 
gem 'coffee-rails', '~> 4.1.0' 
gem 'jquery-rails' 
gem 'turbolinks' 
gem 'jbuilder', '~> 2.0' 
gem 'fullcalendar-rails' 
gem 'sdoc', '~> 0.4.0', group: :doc 


group :development, :test do 
    gem 'byebug' 
    gem 'web-console', '~> 2.0' 
    gem 'spring' 
end 

Вот index.html.erb

<p id="notice"><%= notice %></p> 

<h1>Listing Events</h1> 

<table> 
    <thead> 
    <tr> 
     <th>Title</th> 
     <th>Description</th> 
     <th>Start time</th> 
     <th>End time</th> 
     <th colspan="3"></th> 
    </tr> 
    </thead> 

    <tbody> 
    <% @events.each do |event| %> 
     <tr> 
     <td><%= event.title %></td> 
     <td><%= event.description %></td> 
     <td><%= event.start_time %></td> 
     <td><%= event.end_time %></td> 
     <td><%= link_to 'Show', event %></td> 
     <td><%= link_to 'Edit', edit_event_path(event) %></td> 
     <td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td> 
     </tr> 
    <% end %> 
    </tbody> 
</table> 

<br> 

<%= link_to 'New Event', new_event_path %> 

<br> 

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

Вот файл index.json.jbuilder

json.array!(@events) do |event| 
    json.extract! event, :id, :title, :description 
    json.start event.start_time 
    json.end event.end_time 
    json.url event_url(event, format: :html) 
end 

Вот это events.js.coffee

# Place all the behaviors and hooks related to the matching controller here. 
# All this logic will automatically be available in application.js. 
# You can use CoffeeScript in this file: http://coffeescript.org/ 
# 
# 
$(document).ready -> 
    $("#calendar").fullCalendar(

) 

Вот приложения js и css файлы;

// This is a manifest file that'll be compiled into application.js, which will include all the files 
// listed below. 
// 
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 
// 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// compiled file. 
// 
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 
// about supported directives. 
// 
//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
//= require fullcalendar 
//= require_tree . 

/* 
* This is a manifest file that'll be compiled into application.css, which will include all the files 
* listed below. 
* 
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
* 
* You're free to add application-wide styles to this file and they'll appear at the top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
*= require_self 
*= require_tree . 
*= require fullcalendar 
*/ 

Я не знаю, если это имеет значение, но когда я эшафот событий рельсы создали events.coffee папку, но я изменил его events.js.coffee как в примере. Все файлы js и css загружаются при загрузке индексной страницы, но не отображаются календари на странице

+0

Возможный дубликат [Rails 4 с полным набором приложений init] (http://stackoverflow.com/questions/29912361/rails-4-with-fullcalendar-app-init) –

+0

Но ответа нет? – Shalafister

+0

проверьте свою консоль браузера, возможно, возникнет проблема с moment.js, если она не загружена, вы должны добавить ее с этим камнем [https://github.com/derekprior/momentjs-rails] –

ответ

2

При загрузке страниц с turbolinks событие, готовое к документу, не будет запущено. Вот документ turlolinks events, это может вам помочь.

+0

Но если я вытащу gem turbolinks и // = требую turbolinks из файла приложения js. Он по-прежнему не показывает календарь – Shalafister

+0

Во-первых, убедитесь, что ваш вызов функции будет запущен. Во-вторых, похоже, что ваш fullCalendar вызывает отсутствие параметров. Вот пример: http://fullcalendar.io/ вызов fullCalendar на примере: http://fullcalendar.io/js/home.js?2.3.1 – crazyjin

+0

Спасибо за вашу помощь, я это сделал – Shalafister

Смежные вопросы