PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] How rails render works in controller? Why something it doesn't use layout?

 May 18, 2022     actioncontroller, layout, partial, render, ruby-on-rails     No comments   

Issue

I tried to write render in an action, but layout behavior is different, why?

def show
   # assuming we have a partial in app/views/shared/_panel_show.html.erb
   #render "shared/_panel_show" # have layout
   #render "/shared/_panel_show" # without layout
   #render "shared/panel_show" # Template is missing
   #render :partial => "shared/panel_show" # without layout
   render :partial => "/shared/_panel_show",:layout => "application" # have layout
end

I want to render a partial and follow controller layout.


Solution

The whole point of a partial is that it only renders a part of a view and renders it without any layout.

I would suggest creating a new view (and action in our controller), say shared/full_panel_show, which just renders the partial.

<%= render :partial => 'shared/panel_show' %>

Now in your controller render the new view:

def show
  render :action => 'shared/full_panel_show'
end

Depending on what you are doping with the show view, you could just render the partial from it's view instead.



Answered By - Mike Sutton
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing