In my app/assets/javascripts/components/navbar.js.jsx.erb
I can write something like this in the render function of my component (I'm using the gem react-rails):
class Navbar extends React.Component {
render() {
return(
<div className="navbar-header">
<ul>
<li>
<%= link_to root_path, className: 'navbar-brand' do %>
<span className='glyphicon glyphicon-home'></span>
<%= I18n.t('menu.now') %>
<% end %>
</li>
<li><%= link_to I18n.t('menu.archive'), archive_path%></li>
</ul>
</div>
);
}
}
All works fine except for the link_to
with block, which gives me a syntax error:
syntax error, unexpected keyword_end, expecting ')'
If I remove the block all works fine. Any idea?
PS: To use the Rails helpers, I have added these lines in config/initializers/assets.rb
:
# Include Rails helpers in the assets pipeline
Rails.application.config.assets.configure do |env|
env.context_class.class_eval do
include ActionView::Helpers
include Rails.application.routes.url_helpers
end
end