syntax error, unexpected ',', expecting ')' - Rails 4

0

The Rails interpreter is sending me this message in the following line of code:

...
<li>
  <%= form_tag("search", { method: "get", class: "navbar-form navbar-right", role: "search" }) do %>
    <div class="inner-addon right-addon">
      <i class="glyphicon glyphicon-search"></i>
      <%= text_field_tag (:q, nil , { class: "form-control", height: "25", width: "25" } ) %>
    </div>
  <% end %>
<li>
...

There must be something wrong with the hash of form_tag or text_field_tag but I can not identify

    
asked by anonymous 03.08.2014 / 16:12

1 answer

4

The problem:

text_field_tag (:q, nil , { class: "form-control", height: "25", width: "25" } )

Put simply, you have the following:

funcao (1, 2, 3)

Note the space before opening the parentheses. This is critical. Ruby allows you to pass arguments to a function if no parentheses are used, and at the same time allows the use of parentheses to group simple expressions, such as (1+5)*2 . What happens there is that because of this space he tries to read as if he had passed a single argument: the expression inside the parentheses. And there's the problem, not to have a comma in the middle of the expression. Correction:

funcao(1, 2, 3)

Or if you prefer:

funcao 1, 2, 3

Note, in the particular case of passing a hash as the last argument of the function, you can omit the keys to improve readability. If you want, you can still write like this:

text_field_tag(:q, nil, class: "form-control", height: "25", width: "25")
    
04.08.2014 / 13:14