| View previous topic :: View next topic |
| Author |
Message |
fa00026
Joined: 20 Feb 2009 Posts: 29
|
Posted: Thu Mar 19, 2009 8:51 pm Post subject: Beginner/ change the time in datetime function |
|
|
Hello,
I am using Ruby 1.6, Rails 2.2, netbeans 6.5.
I am using the datetime function to build up a forum, I have problem as when I enter a comment where the date and time apper with, the time appears not as the time in my computer, I wish some help in that.
this the migrate data base
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :post_id
t.datetime :created_at
t.text :comment
t.timestamps
end
end
def self.down
drop_table :comments
end
end
***********************************
and this the controller
class PostsController < ApplicationController
# GET /posts
# GET /posts.xml
def index
@posts = Post.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
@post_comments = @post.comments.collect
flash[:post_id] =@post.id
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@post) }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
format.html { redirect_to(@post) }
format.xml { head k }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head k }
end
end
# Adding a comment
def post_comment
@comment = Comment.new(
"post_id" => flash[:post_id],
"created_at" => Time.now,
"comment" => params[:comment]['comment']
)
flash[:notice] = 'Comment was successfully added.' if @comment.save
redirect_to :action => 'show', :id => flash[:post_id]
end
end
************
And the show view
<p>
<b>Title:</b>
<%=h @post.title %>
</p>
<p>
<b> Body:</b>
<%=h @post.body %>
</p>
<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Back', posts_path %>
<hr>
<h4>Comments</h4>
<ul>
<% @post_comments.each do |comment| %>
<li><%= h comment.comment %><br>
<div style="color: #999; font-size: 8pt">
Posted on <%= comment.created_at.strftime("%B %d, %Y at %I:%M %p") %>
</div>
</li>
<% end %>
</ul>
<% form_tag :action => 'post_comment' do %>
<p><label for="comment_comment">Comment</label><br/>
<%= text_area 'comment', 'comment' %></p>
<%= submit_tag "Post" %>
<%end%> |
|
| Back to top |
|
 |
MarkDavoren
Joined: 12 Feb 2009 Posts: 3
|
Posted: Fri Mar 20, 2009 5:29 pm Post subject: |
|
|
Hi,
Is the time off by an exact number of hours (or half hour)? If so, have you checked the timezone set up?
You can set the timezone of the app in environment.rb, e.g.,
config.time_zone = 'Pacific Time (US & Canada)'
For a list of timezones, you can do
rake time:zones:all
Hope this helps,
Mark. |
|
| Back to top |
|
 |
fa00026
Joined: 20 Feb 2009 Posts: 29
|
Posted: Thu Apr 09, 2009 2:12 pm Post subject: |
|
|
Hello I have tried what you have told me, but I want the time zone to be for London so the value must be config.time_zone ='UTC +00:00' , but it changed nothing at all. and now the gap is one complete hour.
Any ideas .
thanks a lot |
|
| Back to top |
|
 |
Brandon Hauff Posted via mailing list.
|
Posted: Thu Apr 09, 2009 2:16 pm Post subject: Beginner/ change the time in datetime function |
|
|
You might try:
config.time_zone = 'London'
You can run: rake time:zones:all to see the valid time zones, and I am
not sure you can use the UTC ... options.
| Quote: | -----Original Message-----
From: fa00026 [mailto:address-removed]
Sent: Thursday, April 09, 2009 9:13 AM
To: address-removed; address-removed
Subject: Beginner/ change the time in datetime function
Hello I have tried what you have told me, but I want the time zone to
be for London so the value must be config.time_zone ='UTC +00:00' ,
| but
| Quote: | it changed nothing at all. and now the gap is one complete hour.
Any ideas .
thanks a lot
|
|
|
| Back to top |
|
 |
fa00026
Joined: 20 Feb 2009 Posts: 29
|
Posted: Thu Apr 09, 2009 2:21 pm Post subject: |
|
|
I have used London, but still the gap is one hour earlier, now it is 3:21 in london, whle in my project it ios 2:21 ??
What can I do ?
Thanks |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|