2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails console でrenderの返り値を確認する

Last updated at Posted at 2019-09-03

rails console でrenderの返り値を確認する

たとえば、app/views/users/index.erbrenderした時の返り値のHTMLをrails consoleで確認したい場合

view = ActionView::Base.new('app/views/user', {},  ActionController::Base.new)
view.render(file: 'index.erb')

インスタンス変数を渡したい場合

renderのキーワード引数localsで渡してあげる

posts = Post.all

view = ActionView::Base.new('app/views/user', {},  ActionController::Base.new)
view.render(file: 'index.erb', locals: { :@users => [], :@posts => posts })

jbuilderでもできる

app/views/users/index.json.jbuilderPをrenderした時の返り値のHTMLをrails consoleで確認したい場合

posts = Post.all

view = ActionView::Base.new('app/views/user', {},  ActionController::Base.new)
view.render(file: 'index.json.jbuilder', locals: { :@users => [], :@posts => posts })
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?