Ask A Question

Notifications

You’re not receiving notifications from this thread.

eval issue in Rails view

Mark Nelson asked in Rails

Any idea why the following code :

<% model_set = instance_variable_set("@#{table_name}", eval("#{model_name}.all")) %>

produces this runtime error:

(eval):1: syntax error, unexpected '.'

The code correctly sets the instance variable @countries to the output from executing Country.all in the console or when using byebug (model_name is "Country" and table_name is "countries").

Should this be in a helper anyway?

Thanks in advance for assistance.

Reply

This was due to erroneous check in a containing loop which caused a blank model name to be used in the eval. The code is fine.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.