0
0
Ruby on Railsframework~10 mins

Convention over configuration principle in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Rails model using convention over configuration.

Ruby on Rails
class User < ApplicationRecord
  # Rails automatically maps this model to the [1] table
end
Drag options to blanks, or click blank then click option'
Amembers
Buser_data
Caccounts
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a singular table name instead of plural
Using a custom table name without configuration
2fill in blank
medium

Complete the code to create a controller action that renders the default view using Rails conventions.

Ruby on Rails
class PostsController < ApplicationController
  def index
    @posts = Post.all
    render [1]
  end
end
Drag options to blanks, or click blank then click option'
Anil
B:show
C:index
D:new
Attempts:
3 left
💡 Hint
Common Mistakes
Explicitly rendering a different view name
Using render with a symbol that does not match the action
3fill in blank
hard

Fix the error in the route definition by completing the blank with the correct Rails convention.

Ruby on Rails
Rails.application.routes.draw do
  resources :[1]
end
Drag options to blanks, or click blank then click option'
Apost
Bposts
CPost
DPosts
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or capitalized resource names in routes
Mixing case sensitivity in route names
4fill in blank
hard

Fill both blanks to define a model with a custom table name using Rails conventions.

Ruby on Rails
class [1] < ApplicationRecord
  self.table_name = '[2]'
end
Drag options to blanks, or click blank then click option'
AUserProfile
Buser_profiles
CUserprofiles
Duserprofile
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or camel case for the table name
Not setting self.table_name when the table name differs
5fill in blank
hard

Fill all three blanks to complete a Rails migration that creates a table following conventions.

Ruby on Rails
class Create[1] < ActiveRecord::Migration[6.1]
  def change
    create_table :[2] do |t|
      t.string :[3]
      t.timestamps
    end
  end
end
Drag options to blanks, or click blank then click option'
AProducts
Bproducts
Cname
Dproduct_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or lowercase class names
Using camel case for table names
Using complex or non-standard column names