resources :students
> rake db:migrate Ans: > rake db:rollback
Ans: <%= link_to "To Students Index", students_path %>
C:\>irb irb(main):001:0> c = 20 => 20 irb(main):002:0> f = 9 * c / 5 + 32 => 68 irb(main):003:0> print "The Celsius temperature is ", c, ".\n" The Fahrenheit temperature is 20 => nil irb(main):003:0> print "The Fahrenheit temperature is ", f, ".\n" The Fahrenheit temperature is 68 => nil irb(main):003:0> puts "The Celsius temperature is " + c.to_s + "." The Fahrenheit temperature is 20 => nil irb(main):003:0> puts "The Fahrenheit temperature is " + f.to_s The Fahrenheit temperature is 68 => nilEnter ^C to exit irb.
c = 20 f = 9 * c / 5 + 32 print "The Celsius temperature is ", c, ".\n" print "The Fahrenheit temperature is ", f, ".\n" puts "The Celsius temperature is " + c.to_s + "." puts "The Fahrenheit temperature is " + f.to_s + "."Save these commands and exit the Command Line Editor.
C:\>ruby c2f.rb The Celsius temperature is 20. The Fahrenheit temperature is 68. The Celsius temperature is 20. The Fahrenheit temperature is 68.
@c = 20 @f = 9 * @c / 5 + 32Replace the HTML code in index.html.erb with this source code:
<html> <head> <title>Cel To Fahr Example</title> </head> <body> <h1>Cel To Fahr Example</h1> <p>Celsius Temperature: <%= @c %></p> <p>Fahrenheit Temperature: <%= @f %></p> </body> </html>
C:\> cd railsprojects\Census C:\> rails console Loading development environment: (Rails 3.2.8) >>Now you can enter Ruby commands as you did with irb. The advantage of this context is that all of the classes defined by the scaffold software are available.
p = Person.first p.name p.gender p.age p.gender = "F" p.save s = Person.new s.name = 'Walter' s.gender = 'M' s.age = 45 s.saveNow shut down the console with ^C and start the server and check the database with your browser to see whether the changes actually made it to the database.
load 'update.rb'
rake db:seed
c = 20 f = 9 * c / 5 + 32 puts f
input = STDIN.gets c = input.chomp.to_i f = 9 * c / 5 + 32 puts f
c = 20 f = 9 * c / 5 + 32 puts fto
c = 20 @f = 9 * c / 5 + 32This code is placed into the controller method corresponding to the view that will contain the output. Then put this ERB code on the view page:
<%= @f %>