0

The question is answered elsewhere, (how to render partial on everything except a certain action) but does not apply to a Rails engine, which in my case shares the application controller. I don't want my partial "_homeHeader.html.erb" to appear on the pages in the engine. The Engine is rapidfire, a survey. I tried

<%=render :partial =>'layouts/homeHeader' unless {controller => 'rapidfire'} %}

But that blocked the partial everywhere. The header contains a login - logout, which conflicts with the engine. I also tried putting a dummy "_homeHeader.html.erb" in the views folder for rapidfire, but that didn't work; I'm guessing the layout view has precedence.

At the suggestion of Michael I fixed the syntax to

<%= render :partial =>'/layouts/homeHeader' unless (controller.controller_name == "rapidfire/question_groups") %> 

but it didn't work. it's still choking on a login with this error:

undefined local variable or method `destroy_user_session_path' for #<#<Class...
Community
  • 1
  • 1
Tom Connolly
  • 674
  • 1
  • 5
  • 18

1 Answers1

1

It's a syntax issue with the unless statement. You're comparing a hash, when you just need a simple condition.

Try this instead:

<%= render :partial => "layouts/homeHeader" unless (controller.controller_name == "rapidfire") %>

Note that we're using the recommended method to determine the name of the controller. See Can I get the name of the current controller in the view? for some additional information.

Community
  • 1
  • 1
Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
  • I fixed the syntax – Tom Connolly May 09 '16 at 18:47
  • No Michael. I revised my post. Thanks – Tom Connolly May 09 '16 at 18:56
  • That's a different issue, I think. It won't have anything to do with the original question, "How to block a partial in Rails 4 engine". If you can create a new question and post the code for the view and the code for the partial, that would be a good way to handle it the new error. – Michael Gaskill May 09 '16 at 19:00
  • Actaully, it's supposed to block the signin that resides in the partial. So my quest is how to block the partial. It's the original error, and the original question. – Tom Connolly May 09 '16 at 19:01
  • None of that information is included in the question. Please post the code to your a) controller, b) layout, and c) views, so that we can see what's going on. – Michael Gaskill May 09 '16 at 19:10
  • Sorry to seem to be obstinate, but the error happens because the logout and login links appear on the partial. If I could block the partial from launching, the error would go away. I want to block the partial. It is not being blocked with the code you showed me. – Tom Connolly May 10 '16 at 17:00
  • Yes, and I need all of the things that I asked you to post in order to figure out exactly what's going on. I need to see these 4 things added to your question: 1) the controller code, b) the layout, c) any views that are involved, and d) the complete error message with backtrace. If you help me to help you, I'm sure that we can find a solution. – Michael Gaskill May 10 '16 at 17:02
  • Thanks to your comments I am now aware that my desire to block the partial instead of finding out why it caused an error was the wrong approach. While trying to solve the issue by myself I discovered a few things I don't like about the gem features, and decided to drop it. Thanks Michael Gaskill – Tom Connolly May 13 '16 at 14:38