Shaun Hughston
Shaun Hughston

Reputation: 13

Rails Helper Syntax Errors

I am trying to pull in a field to my homepage view, which has a significant JS component (it is an apartment bookings calendar).

In the index.html.erb file, there is a js variable called 'sections', which defines what displays on a given column in the calendar being displayed. I have been testing it with static values, but what I need to do is display the apartment names, which are held in a db field.

I am using a helper to try to achieve this, but I am getting two errors:

syntax error, unexpected keyword_do, expecting keyword_end <% clients.each do |a| %>

and

syntax error, unexpected tSTRING_DEND, expecting keyword_end

I'd like to understand better what is causing these errors, and how to correct the code as below:

module HomeHelper
     def sections(client)
      <% clients.each do |a| %>
    {key: <%= a.id, label: <%= a.appartmentaddress %>}
    <% end %>
    end 
    end

Upvotes: 0

Views: 113

Answers (1)

dstrants
dstrants

Reputation: 7705

Rails helpers are ruby scripts. You don't need to use erb syntax inside them.

To be honest I do not really get what you are trying to do and if a helper is the best place to do this but just try to remove the <% %> from your code and check if you 'll get rid of the syntax errors.

Upvotes: 1

Related Questions