Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check which controller is used to render a partial in Rails?

I have a simple partial for my footer that looks like this:

<footer class="footer">
  <nav>
    <ul>
      <li><%= link_to "Download History", report_histories_path(format: "csv") %>
      <li><%= link_to "Help", help_path %></li>
      <li><%= link_to "About", about_path %></li>
    </ul>
  </nav>
</footer>

The first link allows the user to download some data used to power reports as a CSV, but I only want this to link to appear if the reports_controller is used to render the partial.

I've tried using

<% if params[:reports] %>
  <li><%= link_to "Download History", report_histories_path(format: "csv") %>
<% end %>

as well as

<% if current_page?(url_for(:controller => 'reports')) %>
  <li><%= link_to "Download History", report_histories_path(format: "csv") %>
<% end %>

but neither show the link.

like image 750
nicholas79171 Avatar asked Nov 20 '25 14:11

nicholas79171


1 Answers

You can use params[:controller] for that. Also, params[:action] will contain current action.

like image 173
EugZol Avatar answered Nov 22 '25 04:11

EugZol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!