PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label content-for. Show all posts
Showing posts with label content-for. Show all posts

Wednesday, May 18, 2022

[FIXED] How can I yield a "future" content_for tag in Rails 3?

 May 18, 2022     content-for, partial, ruby-on-rails-3, templates, yield     No comments   

Issue

I have a template with 2 partials. In the first one, I am yieleding content which is only defined in the second partial (with a content_for tag). The problem is that the yield does not recognize that content yet since it was not defined.

If I reverse the order of the partials the yield recognized the content, yet the layout is not as I desire obviously...

Is there a way to do this? Thank you.


Solution

Okay, this was actually an easy fix. I moved the second partial into a content_for block placed above the first partial, and then just yielded it instead of declaring it as a partial.



Answered By - Indigon
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how to render partial on everything except a certain action

 May 18, 2022     content-for, partial, render, ruby-on-rails-3     No comments   

Issue

I have a _header.html.erb partial which is where I put my navbar

on my launch page I don't want to display the navbar.

this is the body of application.html.erb

<body>
<%= render 'layouts/header' %>
<div id="container">
    <%= yield %>
</div>

</body>

How do I render it on every action except specific actions on specific controllers?


Solution

Replace your render with this:

<%= render 'layouts/header' unless @disable_nav %>

Then you can simply set disable_nav to true in any controller action you like:

def landing_page
  @disable_nav = true
end

As a before_filter, which I'd encourage over the above:

application_controller.rb

def disable_nav
  @disable_nav = true
end

my_controller

before_filter :disable_nav, only: [:landing_page]


Answered By - Damien Roche
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

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
All Comments
Atom
All Comments

Copyright © PHPFixing