Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Javascript and Ruby on Rails DB Model to account for the *reserved word* 'end' it is now 'ends' #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/assets/javascripts/full_calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ initialize_calendar = function() {
},

eventDrop: function(event, delta, revertFunc) {
event_data = {
event_data = {
event: {
id: event.id,
start: event.start.format(),
end: event.end.format()
ends: event.end.format()
}
};
$.ajax({
Expand All @@ -39,7 +39,7 @@ initialize_calendar = function() {
type: 'PATCH'
});
},

eventClick: function(event, jsEvent, view) {
$.getScript(event.edit_url, function() {
$('#event_date_range').val(moment(event.start).format("MM/DD/YYYY HH:mm") + ' - ' + moment(event.end).format("MM/DD/YYYY HH:mm"))
Expand All @@ -52,4 +52,3 @@ initialize_calendar = function() {
})
};
$(document).on('turbolinks:load', initialize_calendar);

4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]

def index
@events = Event.where(start: params[:start]..params[:end])
@events = Event.where(start: params[:start]..params[:ends])
end

def show
Expand Down Expand Up @@ -34,6 +34,6 @@ def set_event
end

def event_params
params.require(:event).permit(:title, :date_range, :start, :end, :color)
params.require(:event).permit(:title, :date_range, :start, :ends, :color)
end
end
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class Event < ApplicationRecord
attr_accessor :date_range

def all_day_event?
self.start == self.start.midnight && self.end == self.end.midnight ? true : false
self.start == self.start.midnight && self.ends == self.ends.midnight ? true : false
end
end
2 changes: 1 addition & 1 deletion app/views/events/_event.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ date_format = event.all_day_event? ? '%Y-%m-%d' : '%Y-%m-%dT%H:%M:%S'
json.id event.id
json.title event.title
json.start event.start.strftime(date_format)
json.end event.end.strftime(date_format)
json.end event.ends.strftime(date_format)

json.color event.color unless event.color.blank?
json.allDay event.all_day_event? ? true : false
Expand Down
12 changes: 6 additions & 6 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<%= f.input :title %>
<%= f.input :date_range, input_html: { class: "form-control input-sm date-range-picker" } %>
<%= f.input_field :start, as: :hidden, value: Date.today, class: 'form-control input-sm start_hidden' %>
<%= f.input_field :end, as: :hidden, value: Date.today, class: 'form-control input-sm end_hidden' %>
<%= f.input_field :ends, as: :hidden, value: Date.today, class: 'form-control input-sm end_hidden' %>
<%= f.input :color, as: :select, collection: [['Black','black'], ['Green','green'], ['Red','red']] %>
</div>

<div class="form-actions">
<%= f.button :submit %>
<%= link_to 'Delete',
event,
method: :delete,
class: 'btn btn-danger',
data: { confirm: 'Are you sure?' },
<%= link_to 'Delete',
event,
method: :delete,
class: 'btn btn-danger',
data: { confirm: 'Are you sure?' },
remote: true unless @event.new_record? %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/events/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ json.array! @events do |event|
json.id event.id
json.title event.title
json.start event.start.strftime(date_format)
json.end event.end.strftime(date_format)
json.end event.ends.strftime(date_format)
json.color event.color unless event.color.blank?
json.allDay event.all_day_event? ? true : false
json.update_url event_path(event, method: :patch)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160814032341_create_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def change
create_table :events do |t|
t.string :title
t.datetime :start
t.datetime :end
t.datetime :ends
t.string :color

t.timestamps
Expand Down