Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question