At the bottom of the controller, define this private method
def get_time
t = Time.now
h = t.hour
min = t.min
s = t.sec
m = t.mon
d = t.day
y = t.year
if h == 0
h = 12
am_pm = "AM"
elsif h < 12
am_pm = "AM"
elsif h == 12
am_pm = "PM"
elsif h > 12
h = h - 12
end
@time_string = "%d/%d/%d %d:%02d:%02d @s" %
[h, min, s, m, d, y % 100, am_pm]
end
At the top of the controller, enter this line:
before_action :get_time
In the layout page application.html.erb above the yield statement, enter these lines:
<p class="r"><%= @time_string %></p>
In the controller specific style file add this line:
p.r { text-align: right }
- What is a migration?
Ans: The Rails migrations that we have seen modify a database table: (a) create a table, (b) add a column to a table,
(c) remove a column from a table, (d) drop a table entirely.
- How can you fix a mistake that you made in a migration?
Ans: If you catch the mistake before you run rake db:migrate, you can simply edit the migration file to correct the
mistake. If you run rake db:migrate before you catch the mistake, run
rake db:rollback, fix the mistake in the
migration file, and run rake db:migrate again.