2

I am migrating an application in Rails 3.2 to a single-page-application architecture, using Backbone.js through the gem backbone-on-rails.

My application views have actually some forms using form_for, like this simple example:

<%= form_for :filter do |f| %>
    <div>
        <%= f.label :document, t('tags.label.entity_document') %>
        <%= f.text_field :document %>
    </div>
    <div>
        <%= f.label :name, t('tags.label.name') %>
        <%= f.text_field :name %>
    </div>
    ... and so on
<% end %>

I have seen Rails 3.1 Asset pipeline has a feature of compiling JST files and that it is possible to cascade several compilers together to compile the template, in my case I want to compile this ERB form file in the assets.

So I moved the form erb file to the assets folder with the name app/assets/templates/index.jst.ejs.erb and I am receiving the following compile error message:

compile error
/Users/rmi/Workspace/cbs-backbone/app/assets/templates/entities/index.jst.ejs.erb:2: syntax error, unexpected ')'
...h', :method => 'get'} do |f| ).to_s)
                              ^
/Users/rmi/Workspace/cbs-backbone/app/assets/templates/entities/index.jst.ejs.erb:52: syntax error, unexpected kENSURE, expecting ')'
/Users/rmi/Workspace/cbs-backbone/app/assets/templates/entities/index.jst.ejs.erb:54: syntax error, unexpected kEND, expecting ')'
  (in /Users/rmi/Workspace/cbs-backbone/app/assets/templates/entities/index.jst.ejs.erb)

this same error happens also with this simple following code:

<%=  [1,2].each do |element| %>
   aaa
<% end %>

does

compile error
/Users/rmi/Workspace/cbs-backbone/app/assets/templates/entities/sbrabous.jst.ejs.erb:1: syntax error, unexpected ')'
_erbout = ''; _erbout.concat((  [1,2].each do |element| ).to_s)
                                                         ^

so it seems to be happening with every ruby block.

I have configured my rails application to use {{ }} as EJS open/close tag, as shown in this previous question https://stackoverflow.com/a/9282744/1216027 , so <% should be ERB processing, and it is really working for ruby commands that does not need a block.

Is it possible to compile these ERB code in the assets? How?

Community
  • 1
  • 1
viniciuscb
  • 123
  • 1
  • 7

1 Answers1

0

I had the same problem when used <%= ... -%> syntax in js.erb asset file. Using <%= ... %> fixed it.

Also try skip = for the loop call

<%  [1,2].each do |element| %>
   aaa
<% end %>
aristofun
  • 375
  • 3
  • 18