Skip to content

Instantly share code, notes, and snippets.

@jmccaffrey
Last active April 1, 2016 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmccaffrey/ca884aa87ec06468f8be22bd7f89f336 to your computer and use it in GitHub Desktop.
Save jmccaffrey/ca884aa87ec06468f8be22bd7f89f336 to your computer and use it in GitHub Desktop.
simple_calendar_demo_on_runnable

Problem:

How do you change the date format that is displayed in the calendar for simple_calendar gem?

kylesandhage [1:22 PM] https://github.com/excid3/simple_calendar/blob/master/app/views/simple_calendar/_month_calendar.html.erb

Approach:

Play with the demo app and see what is possible

My finished product

http://code.runnable.com/me/Vv7HadTUQPN72Xly

you should see a calendar with days of the week shown in 2 formats default 2016-04-01 Day of month 1

screenshot

Steps I took to make it work

I started with their vanilla rails project http://code.runnable.com/

  • click rails icon (it will create a new project for you)

  • then I cloned the sample ajax app into another dir

    git clone https://github.com/excid3/simple_calendar-ajax-example.git

then changed the run command (gear next to the run button) to cd ../simple_calendar-ajax-example; rails server -p 80 -b 0.0.0.0

took me a bit to realize that I needed to bind to 0.0.0.0
  I thought it was a permissions thing

it works! (but you can't really see it because of a css issue I think)

to make the code viewable in the editor
  I made a symlink (from inside the rails_repo dir)
    ```ln -s /root/simple_calendar-ajax-example calendar_app```

  (now that the symlink is there, this would also work for the run command)
    ```cd calendar_app/; rails server -p 80 -b 0.0.0.0```
  
once it is running, it doesn't really show in the main window, probably some css issue
  but you can pop it out by clicking the pop out arrow
    http://web-e35ee47f-b815-481e-99c2-776381f87779.runnablecodesnippets.com/

Coding

Ok, now we have a running demo, but it displays the dates in

How can we change that?

this gave me a clue that we just need to play with the date object and add some formatting http://stackoverflow.com/questions/33302539/rails-4-x-simple-calendar-gem-create-new-record-on-click-in-calendar-cell

Which file? (calendar_app is our symlink) from the editor view calender_app/app/views/events/_calendar.html.erb

<%= month_calendar events: events do |date, events| %>
 default <%= date %> <br/>
 Day of month <%= date.strftime('%e') %>

 <% events.each do |event| %>
   <div>
     <%= event.name %>
   </div>
 <% end %>
<% end %>

When I came back and tried it again

  • the run button was just running rails server -p 80
  • instead of cd ../simple_calendar-ajax-example; rails server -p 80 -b 0.0.0.0 even though that is what was in the run command entry I copied it, deleted it, tabbed away, pasted it back in, and then it worked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment