E
E
eldar_m2019-02-17 12:55:29
Ruby on Rails
eldar_m, 2019-02-17 12:55:29

Why does Controller.object_id return the same value for different requests?

I can't figure out why self.class.object_id - returns the same value inside `new` and `create` actions.
Although, as I understand it, Rails creates a new controller instance for each request - i.e. the object_id must be different.

class ArticlesController < ApplicationController
      def new
        p self.class.object_id

        @article = Article.new
      end

      def create
        p self.class.object_id

        @article = Article.new(article_params)

        if @article.save
          redirect_to @article
        else
          render 'new'
        end
      end

      private
      def article_params
        params.require(:article).permit(:title, :text)
      end
    end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eldar_m, 2019-02-17
@eldar_m

self.class.object_id - Points to the ApplicationController class.
it was necessary to compare class instances - self.object_id.
and everything works.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question