Câu hỏi phỏng vấn Ruby on Rails
Câu hỏi

What Are Filters?

Câu trả lời

What Are Filters in Ruby on Rails?

Filters in Ruby on Rails are methods that are executed before, after, or around a controller action. They allow you to perform common tasks across multiple actions in a controller, such as authentication, authorization, logging, or setting up data for the view.

Filters are defined using the following methods in a controller:

  • before_action: Executes the specified filter method before the action is executed.
  • after_action: Executes the specified filter method after the action is executed.
  • around_action: Executes the specified filter method around the action, allowing you to perform tasks before and after the action is executed.

Here's an example of how to use filters in a controller:

class PostsController < ApplicationController
  before_action :authenticate_user!, only: [:new, :create, :edit, :update, :destroy]
  before_action :set_post, only: [:show, :edit, :update, :destroy]

  def index
    @posts = Post.all
 ...
middle

middle

Gợi ý câu hỏi phỏng vấn

entry

Mention what is Rails Migration?

senior

Is Rails Scalable?

middle

What is the purpose of the rakefile available in the demo directory in Ruby?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào