This is a follow up question to: Rendering different views in one action
The error I am getting is:
Template is missing
Missing template items/show, application/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.
It should be noted, that I copied the show.html.erb
file to two files show_with_edit.html.erb
and show_with_star.erb
, and deleted show.html.erb
to avoid duplicates.
My Code in posts_controller.rb
def show
if signed_in?
show_signed_in
else
show_not_signed_in
end
end
def show_signed_in
#add methods here
@post = Post.find(params[:id])
respond_to do |format|
format.html # show_with_edit.html.erb
format.json { render json: @post }
end
render 'show_with_edit'
end
def show_not_signed_in
#add methods here
@post = Post.find(params[:id])
respond_to do |format|
format.html # show_with_star.html.erb
format.json { render json: @post }
end
render 'show_with_star'
end
I am aware that for now the two different views are identical, I just put there different text for now. Once I have this nailed down I'll add to each view its own methods and content etc.
You've put render in the wrong places.
should be
Note the
render
that is moved to the format.html block.The same applies for show_not_signed_in.
please check your route.rb file is properly written , eg: consider following
collection you write the method that is get or post