Reputation: 4093
Im trying to render a specific layout when the form is NOT properly filled:
Inside my views/layouts I've:
My controller:
class UsersController < ApplicationController
def new
@user = User.new
render layout: "empty" # I wan to re-use this layout is the user is not been saved
end
def create
@user = User.new(user_params)
if @user.save
redirect_to sign_in_path
else
render :new
end
end
def user_params
params.require(:user).permit!
end
end
The thing is that it works it re-renders the new-action when it's not true BUT it uses Application-default layout and NOT the other layout-file called: empty.html.erb
According to Rails guide lines it should work...but not for me :(
Thanks for your time
Upvotes: 1
Views: 1966
Reputation: 1136
In the def create
method, the render :new
is rendering the new.html.erb view using the default layout. You can try
render layout: "empty", template: "users/new"
render
merely "paints" the page according to the layout and template given to it.
redirect_to "new"
will send a request for the new
action.
Upvotes: 4