0

I am trying to build my first Rails application and I'm using Ryan Heath's navigation_helper plugin to give me the current class in my navigation. I built my named routes as follows:

match 'games' => 'games#index', :as => :games
match 'new' => 'games#new', :as => :new
match 'previous' => 'games#previous', :as => :previous
match 'settings' => 'settings#index', :as => :settings

Then in my application_layout I added the following code

<%= navigation([:games, :new, :previous, :settings]).html_safe %>

From what I know of Rails the html_safe should force HTML to be rendered properly, but instead what I get is this:

<ul class="navigation">[&quot;&lt;li class=\&quot;current\&quot;&gt;&lt;a href=\&quot;/games\&quot;&gt;Games&lt;/a&gt;&lt;/li&gt;&quot;, &quot;&lt;li class=\&quot;\&quot;&gt;&lt;a href=\&quot;/new\&quot;&gt;New&lt;/a&gt;&lt;/li&gt;&quot;, &quot;&lt;li class=\&quot;\&quot;&gt;&lt;a href=\&quot;/previous\&quot;&gt;Previous&lt;/a&gt;&lt;/li&gt;&quot;, &quot;&lt;li class=\&quot;\&quot;&gt;&lt;a href=\&quot;/settings\&quot;&gt;Settings&lt;/a&gt;&lt;/li&gt;&quot;]</ul> 

So am I doing something wrong or is the plugin doing something wrong? I know that the plugin was written back in 2.x days which from what I know handled HTML a bit differently, but I just don't know enough.

Dave Long
  • 9,569
  • 14
  • 59
  • 89

2 Answers2

0

You can use raw() method to avoid escaping:

<%= raw(navigation([:games, :new, :previous, :settings])) %>
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
  • Using raw I get the same output. What is the difference between raw and html_safe? – Dave Long Sep 04 '11 at 17:30
  • Check this out: http://stackoverflow.com/questions/4251284/raw-vs-html-safe-vs-h-to-unescape-html – Pavel S. Sep 04 '11 at 17:31
  • Thanks. I think I understand now. Raw seems better for method calls if you don't use parentheses (ex. `raw navigation [:games, :new, :previous, :settings`) whereas html_safe seems better on strings. – Dave Long Sep 04 '11 at 17:35
  • Still getting the same output though no matter which method I use. Always the escaped string – Dave Long Sep 04 '11 at 17:35
0

https://github.com/priceflex/navigation_helper/commit/ad7bf45db1845e9299e9da39cf214866b608dd47 try to use this fork wich fix issues for rails3

Fivell
  • 11,829
  • 3
  • 61
  • 99