1

Can anyone explain why this code:

    <%= form.select(:language_id) do
            Language.all.each do |lang|
                content_tag(:option, lang.name, value: lang.id,
                    onchange: "setThemeAndMode('#{lang.theme}','#{lang.mode}')")
            end
        end
    %>

Errors with this:

undefined method `empty?' for nil:NilClass
Extracted source (around line #22):
20
21
22
23
24
25

        </p>
    </div>
    <%= form.select(:language_id) do
            Language.all.each do |lang|
                content_tag(:option, lang.name, value: lang.id,
                    onchange: "setThemeAndMode('#{lang.theme}','#{lang.mode}')")

I'm very new to Ruby, and believe it to mean that it isn't finding any languages - But the database is full of them. Removing the content_tag and just having an <h3>lang.name</h3> displays correctly. Any help is very much appreciated.

1 Answer 1

2

It is an issue with how you are passing your block. Do this instead

<%= f.select(:language_id) do %>
  <% Language.all.each do |lang| %>
    <%= content_tag(:option, lang.name, value: lang.id,
                     onchange: "setThemeAndMode('#{lang.name}','#{lang.id}')") %>
  <% end %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.