I am trying to render a view + layout based on a condition. The following code seems to work but loses access to @objects set upfront. I call this code in a ProfilesController method Show.
@profiles = Profile.where(:user_id => current_user.id).first
if @profile.nil? == true
render :view => "show",
:layout => "application"
else
render :template => "profiles/my_profile",
:layout => "profiles"
end
Gives output:
undefined method `profiles' for nil:NilClass
How could one render based on a condition and still preserve the previous set @objects (in this case the access to @profiles)
Setting layout in view is not the way to go, its not the rails way and was not advised so even if possible. I changed setting layout in controller action and render the right code in my show partial wich complete solved the issue.