-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
by rendering Jbuilder template in the view
- Loading branch information
Showing
3 changed files
with
31 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
class PagesController < ApplicationController | ||
def index | ||
@comments = Comment.all | ||
|
||
# NOTE: The below notes apply if you want to set the value of the props in the controller, as | ||
# compared to he view. However, it's more convenient to use Jbuilder from the view. See | ||
# app/views/pages/index.html.erb:20 | ||
# | ||
# <%= react_component('App', render(template: "/comments/index.json.jbuilder"), | ||
# generator_function: true, prerender: true) %> | ||
# | ||
# | ||
# NOTE: this could be an alternate syntax if you wanted to pass comments as a variable to a partial | ||
# @comments_json_sting = render_to_string(partial: "/comments/comments.json.jbuilder", | ||
# locals: { comments: Comment.all }, format: :json) | ||
@comments = Comment.all | ||
|
||
# NOTE: @comments is used by the render_to_string call | ||
@comments_json_string = render_to_string("/comments/index.json.jbuilder") | ||
|
||
# @comments_json_string = render_to_string("/comments/index.json.jbuilder") | ||
# NOTE: It's CRITICAL to call respond_to after calling render_to_string, or else Rails will | ||
# not render the HTML version of the index page properly. | ||
respond_to do |format| | ||
format.html | ||
end | ||
# not render the HTML version of the index page properly. (not a problem if you do this in the view) | ||
# respond_to do |format| | ||
# format.html | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters