Last active
November 10, 2015 15:13
-
-
Save aamax/8183d7df1415f87defbc to your computer and use it in GitHub Desktop.
weird datetime issues in rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.time_zone = "Pacific Time (US & Canada)" | |
config.active_record.default_timezone = "Pacific Time (US & Canada)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="notice"><%= notice %></p> | |
<h1>Listing System Logs</h1> | |
<table class="table table-striped"> | |
<thead> | |
<tr> | |
<th>Occurred</th> | |
<th>Action</th> | |
<th>Comment</th> | |
<th>CreatedAt</th> | |
<th colspan="3"></th> | |
</tr> | |
</thead> | |
<tbody> | |
<% @system_logs.each do |system_log| %> | |
<tr> | |
<td><%= system_log.occurred %></td> | |
<td><%= system_log.action %></td> | |
<td><%= system_log.comment %></td> | |
<td><%= system_log.created_at %></td> | |
<td><%= link_to 'Show', system_log %></td> | |
<td><%= link_to 'Edit', edit_system_log_path(system_log) %></td> | |
<td><%= link_to 'Destroy', system_log, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
</tr> | |
<% end %> | |
</tbody> | |
</table> | |
<br> | |
<%= link_to 'New System log', new_system_log_path %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.2.2 :002 > SystemLog.first | |
SystemLog Load (0.6ms) SELECT "system_logs".* FROM "system_logs" ORDER BY "system_logs"."id" ASC LIMIT 1 | |
=> #<SystemLog id: 1, occurred: nil, action: "Loading all Initialized Data", comment: "", created_at: nil, updated_at: nil> | |
2.2.2 :003 > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: system_logs | |
# | |
# id :integer not null, primary key | |
# occurred :datetime | |
# action :string | |
# comment :text | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# | |
class SystemLog < ActiveRecord::Base | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SystemLogsController < ApplicationController | |
before_action :set_system_log, only: [:show, :edit, :update, :destroy] | |
# GET /system_logs | |
# GET /system_logs.json | |
def index | |
@system_logs = SystemLog.all.order(occurred: :desc) | |
end | |
# GET /system_logs/1 | |
# GET /system_logs/1.json | |
def show | |
end | |
# GET /system_logs/new | |
def new | |
@system_log = SystemLog.new | |
end | |
# GET /system_logs/1/edit | |
def edit | |
end | |
# POST /system_logs | |
# POST /system_logs.json | |
def create | |
@system_log = SystemLog.new(system_log_params) | |
respond_to do |format| | |
if @system_log.save | |
format.html { redirect_to @system_log, notice: 'System log was successfully created.' } | |
format.json { render :show, status: :created, location: @system_log } | |
else | |
format.html { render :new } | |
format.json { render json: @system_log.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /system_logs/1 | |
# PATCH/PUT /system_logs/1.json | |
def update | |
respond_to do |format| | |
if @system_log.update(system_log_params) | |
format.html { redirect_to @system_log, notice: 'System log was successfully updated.' } | |
format.json { render :show, status: :ok, location: @system_log } | |
else | |
format.html { render :edit } | |
format.json { render json: @system_log.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /system_logs/1 | |
# DELETE /system_logs/1.json | |
def destroy | |
@system_log.destroy | |
respond_to do |format| | |
format.html { redirect_to system_logs_url, notice: 'System log was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_system_log | |
@system_log = SystemLog.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def system_log_params | |
params.require(:system_log).permit(:occurred, :action, :comment) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment