Skip to content

Commit 03cc621

Browse files
author
vadim
committed
calendar add
1 parent 8109577 commit 03cc621

16 files changed

Lines changed: 6736 additions & 16 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gem 'therubyracer', platforms: :ruby
2525

2626
# Use jquery as the JavaScript library
2727
gem 'jquery-rails'
28-
28+
gem 'jquery-ui-rails'
2929
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
3030
gem 'turbolinks'
3131

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ GEM
5353
jquery-rails (3.0.4)
5454
railties (>= 3.0, < 5.0)
5555
thor (>= 0.14, < 2.0)
56+
jquery-ui-rails (4.0.3)
57+
jquery-rails
58+
railties (>= 3.1.0)
5659
json (1.8.0)
5760
less (2.3.3)
5861
commonjs (~> 0.2.6)
@@ -133,6 +136,7 @@ DEPENDENCIES
133136
haml-rails
134137
jbuilder (~> 1.2)
135138
jquery-rails
139+
jquery-ui-rails
136140
less-rails
137141
less-rails-bootstrap
138142
pg

app/assets/javascripts/application.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
//= require jquery_ujs
1515
//= require turbolinks
1616
//= require_tree .
17+
//= require fullcalendar
18+
//= require jquery.ui.all
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
# Place all the behaviors and hooks related to the matching controller here.
2-
# All this logic will automatically be available in application.js.
3-
# You can use CoffeeScript in this file: http://coffeescript.org/
1+
$ ()->
2+
$('.datepicker').datepicker({
3+
dateFormat: "yy-mm-dd"
4+
})
5+
6+
$('#calendar').fullCalendar({
7+
events: '/events.json'
8+
})

app/assets/stylesheets/application.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
*= require_self
1212
*= require_tree .
1313
*= require twitter/bootstrap
14+
*= require fullcalendar
15+
*= require jquery.ui.all
1416
*/

app/controllers/events_controller.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def edit
2424
# POST /events
2525
# POST /events.json
2626
def create
27-
@event = Event.new(event_params.permit(:name))
27+
@event = Event.new(event_params.permit(:name, :start_at, :end_at))
2828

2929
respond_to do |format|
3030
if @event.save
@@ -62,13 +62,13 @@ def destroy
6262
end
6363

6464
private
65-
# Use callbacks to share common setup or constraints between actions.
66-
def set_event
67-
@event = Event.find(params[:id])
68-
end
65+
# Use callbacks to share common setup or constraints between actions.
66+
def set_event
67+
@event = Event.find(params[:id])
68+
end
6969

70-
# Never trust parameters from the scary internet, only allow the white list through.
71-
def event_params
72-
params[:event]
73-
end
70+
# Never trust parameters from the scary internet, only allow the white list through.
71+
def event_params
72+
params[:event]
73+
end
7474
end

app/models/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Event < ActiveRecord::Base
22
has_and_belongs_to_many :categories
33

4+
validates_presence_of :start_at
45
end

app/views/events/_form.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
%li= msg
88
= f.label :name
99
= f.text_field :name
10+
= f.label :start_at
11+
= f.text_field :start_at, class: 'datepicker'
12+
= f.label :end_at
13+
= f.text_field :end_at, class: 'datepicker'
1014

1115
.actions
1216
= f.submit 'Save'

app/views/events/index.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#calendar
2+
13
%h1 Listing events
24

35
%table
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
json.array!(@events) do |event|
2-
json.extract! event,
3-
json.url event_url(event, format: :json)
2+
json.title event.name
3+
json.start event.start_at.to_i
4+
json.end event.end_at.to_i
45
end

0 commit comments

Comments
 (0)