<%= ... %> <% ... %>Ans: ERB delimiters are used to call Rails helper functions or insert variable values into a view or layout. Use <%= ... %> when calling a Rails method that generates HTML code. Use <% ... %> when calling an ERB control method.
<%= image_tag 'paris.jpg' %>link to the stylesheet stylepage.css. Ans:
<%= stylesheet_link_tag 'stylepage' %>implement a hyperlink with text "Back to Homepage" that jumps to the view homepage in the controller store. Ans:
<%= link_to 'Back to Homepage', store_homepage_path %>
http://localhost:3000/grocery_item/show/25Ans: protocol; server name; port number; controller; action; id
http://localhost:3000/Info/indexAns:
<%= yield %>Ans: It marks where the view is to be inserted into a layout page.
<%= image_tag 'car.jpg' %> <img src="/images/car.jpg" alt="Car" /> <%= image_tag 'dogs/image.jpg' %> <img src="/images/dogs/collie.jpg" alt="Collie" /> <%= image_tag 'car.jpg', :alt => 'Ford Taurus' %> <img src="/images/car.jpg" alt="Ford Taurus" /> <%= image_tag 'car.jpg', :size => '250x200' %> <img src="/images/car.jpg" height="250" width="200" alt="Ford Taurus" /> <%= image_tag 'car.jpg', :width => '250' %> <img src="/images/car.jpg" height="250" alt="Ford Taurus" /> <%= image_tag 'car.jpg', :class => 'carimg' %> <img src="/images/car.jpg" class="carimg" alt="Ford Taurus" />Reference: api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html
<%= stylesheet_link_tag 'styles.css' %> <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/styles.css" > <%= stylesheet_link_tag 'styles' %> <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/styles.css" > <%= stylesheet_link_tag 'dogs/styles' %> <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/dogs/styles.css" > <%= stylesheet_link_tag 'styles', 'dogs/canines' %> <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/styles.css" > <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/dogs/canines.css" > <%= stylesheet_link_tag 'styles', :media => 'print' %> <link rel="stylesheet" type="text/css" media="print" href="stylesheets/styles.css" > <%= stylesheet_link_tag :all, :media => 'print' %> Link to all stylesheets in stylesheets folder.Reference: api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html
<%= link_to 'To Profiles/Show Page', profiles_show_path %> <a href="/profiles/show">To Profile Page</a> <%= link_to 'To Profiles/Show Page', profiles_show_path, :class => 'link' %> <a href="/profiles/show" class="link"> To Profile Page</a> <%= link_to 'To Profiles/Show Page', profiles_show_path, :class => 'link' :id => 'linka' %> <a href="/profiles/show" class="link" id="linka"> To Profile Page</a> <%= link_to 'To Profile/Show Page', profiles_show_path, :confirm => 'Are you sure?' %> <a href="/profiles/show" ">To Profile Page</a> Need JavaScript code to show an alert box.Reference: api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
:string | A string of characters. |
:text | A string of characters, generally longer than a string, which can contain more than one line. |
:integer | A positive, negative, or zero number without a fractional part; for example 238372, -3273, 0. Integers are represented in binary. |
:float | A positive, negative, or zero floating point number, which can contain a decimal point; for example 345.39, -438.86, 0.00. Floats are also represented in binary. |
:decimal | A positive, negative, or zero floating point number, which can contain a decimal point. Decimal numbers are represented in base 10 and are accurate for financial calculations. |
:datetime | A combination type that represents a date and time to the nearest millisecond. |
:timestamp | Used to mark when a row is entered in a database. |
:time | The hour, minute, and second of the time recorded in the database. |
:date | The year, month, and day of the date recorded in the database. |
:binary | Unstructured binary data (sometimes called a BLOB for binary large object). This may be compressed data that is uncompressed when it is retrieved from the database, or it may be image or sound data. |
:boolean | Contains a 0 or 1 that represents false or true. |
rails g scaffold MovieReview movie_name:string \ reviewer_name:string review:text review:integer \ view_date:date straight_to_video:boolean
rake db:migrate
Resource Name | movie_reviews |
Database Table Name | movie_reviews |
Model Name | MovieReview |
Controller Name | MovieReviewController |
View Folder Name | movie_reviews |
URL | http://localhost:3000/movie_reviews |
Resource Name | person |
Database Table Name | people |
Model Name | Person |
Controller Name | PersonController |
View Folder Name | people |
URL | http://localhost:3000/people |
get "info/staff"
resources :movie_reviews
f.date_select :birth_date
f.date_select :birth_date, :start_year => 1983, :end_year => 2015Caution: 1983 and 2015 must not be in quotes because they are integers, not strings.
# Use month numbers instead of names. :use_month_numbers => true # Add month numbers in addition to names. :add_month_numbers => true # Use short form of months: Jan, Feb, Mar, ... :use_short_month => true # Don't include a dropdown menu for days. :discard_day => true # Don't include a dropdown menu for months. :discard_month => true # Don't include a dropdown menu for years. :discard_year => true
validates_presence_of :first_name validates_length_of :student_id, :minimum => 4, :maximum => 4 validates_numericality_of :gpa, :greater_than_or_equal_to => 0.0, :less_than_or_equal_to => 4.0, :only_integer
validates :title, :presence => true validates :email, :uniqueness => true validates :username, :length => { :within => 8..20 } validates :age, :numericality => true validates :age, :numericality => { :only_integer => true } validates :age, :numericality => { :greater_than => 0 }
rails g scaffold Student name:string year:integer birth_date:date gpa:float
School\db\migrate\20110404234401_create_students.rbThis is the migration file that contains the directions for creating the database.
rake db:migrateThis actually creates the database and schema in
School\db\development.sqlite3and
School\db\schema.rbrespectively.