JavaScript isn't enabled in your browser, so this file can't be opened. Enable and reload.
Ruby on Rails Part-II
Sign in to Google
to save your progress.
Learn more
* Indicates required question
You made a spelling mistake while creating a table for bank accounts. Which code would you expect to see in a migration to fix the error?
*
1 point
A
B
C
D
Given this controller code, which choice describes the expected behavior if parameters are submitted to the update action that includes values for the product's name, style, color, and price?
*
1 point
The product will not be updated and the edit template will be rendered.
The product will not be updated and the controller will raise an ActiveModel::ForbiddenAttributes exception.
The product will be updated with the values for name, style, and color, but the value for price will be ignored.
The product will be updated with the values for name, style, color, and price.
In the model User you have the code shown below. When saving the model and model.is_admin is set to true, which callback will be called?
*
1 point
encrypt_data
clear_cache
notify_admin_users
None of these callbacks will be called when is_admin is true.
Review the code below. Which Ruby operator should be used to fill in the blank so that the sort method executes properly?
*
1 point
=>
<==>
<=>
||
Which Rails helper would you use in the application view to protect against CSRF (Cross-Site Request Forgery) attacks?
*
1 point
csrf_protection
csrf_helper
csrf_meta_tags
csrf
How do you add Ruby code inside Rails views and have its result outputted in the HTML file?
*
1 point
Create an embedded Ruby file (.html.erb) and surround the Ruby code with <% %>.
Insert Ruby code inside standard HTML files and surround it with <% %>. The web server will handle the rest.
Create an embedded Ruby file (.html.erb) and surround the Ruby code with <%= %>. Reference
Put the code in an .rb file and include it in a <link> tag of an HTML file.
Where should you put images, JavaScript, and CSS so that they get processed by the asset pipeline?
*
1 point
app/static
app/images
app/assets
app/views
If a model class is named Product, in which database table will ActiveRecord store and retrieve model instances?
*
1 point
product_table
all_products
products_table
products
A Rails project has ActiveRecord classes defined for Classroom and Student. If instances of these classes are related so that students are assigned the ID of one particular classroom, which choice shows the correct associations to define?
*
1 point
A
B
C
D
If the Rails asset pipeline is being used to serve JavaScript files, how would you include a link to one of those JavaScript files in a view?
*
1 point
<script src="/main.js"></script>
<%= javascript_include_tag 'main' %>
<%= javascript_tag 'main' %>
<!-- include_javascript 'main' -->
Which ActiveRecord query prevents SQL injection?
*
1 point
Product.where("name = " << @keyword)
Product.where("name = " + h(@keyword))
Product.where("name = ?", @keyword)
Product.where("name = #{@keyword}")
What is a popular alternative template language for generating views in a Rails app that is focused on simple abstracted markup?
*
1 point
Mustache
Haml
Liquid
Tilt
In Rails, what caching stores can be used?
*
1 point
MemCacheStore, MongoDBStore, MemoryStore, and FileStore
MemoryStore, FileStore, and CacheCacheStore
MemoryStore, FileStore, MemCacheStore, RedisCacheStore, and NullStore
MemoryStore, FileStore, MySQLStore, and RedisCacheStore
In ActiveRecord, what is the difference between the has_many and has_many :through associations?
*
1 point
The has_many: through association is the one-to-many equivalent to the belongs_to one-to-one association.
Both associations are identical, and has_many: through is maintained only for legacy purposes.
The has_many association is a one-to-many association, while has_many: through is a one-to-one association that matches through a third model.
Both are one-to-many associations but with has_many :through, the declaring model can associate through a third model.
Which HTML is closes to what this code would output?
*
1 point
A
B
C
D
What part of the code below causes the method #decrypt_data to be run?
*
1 point
MyModel.first.update(field: 'example')
MyModel.where(id: 42)
MyModel.first.destroy
MyModel.new(field: 'new instance')
When Ruby methods add an exclamation point at the end of their name (such as sort!), what does it typically indicate?
*
1 point
The method executes using "sudo" privileges.
Any ending line return will be omitted from the result.
The method will ignore exceptions that occur during execution.
It is a more powerful or destructive version of the method.
What is the correct way to generate a ProductsController with an index action using only the command-line tools bundled with Rails?
*
1 point
rails generate controller --options {name: "Products", actions: "index"}
rails generate controller --name Products --action index
rails generate controller Products index
rails generate ProductsController --actions index
How would you render a view using a different layout in an ERB HTML view?
*
1 point
<% render 'view_mobile' %>
<% render 'view', use_layout: 'mobile' %>
<% render 'view', layout: 'mobile' %>
<% render_with_layout 'view', 'mobile' %>
In a Rails controller, what does the code params.permit(:name, :sku) do?
*
1 point
It filters out all parameters.
It filters out submitted form parameters that are not named :name or :sku to make forms more secure.
It raises an error if parameters that are not named :name or :sku are found.
It raises an error if the :name and :sku parameters are set to nil.
Submit
Page 1 of 1
Clear form
Forms
This content is neither created nor endorsed by Google.
Report Abuse
Terms of Service
Privacy Policy
Help and feedback
Contact form owner
Help Forms improve
Report