New Discussion

Notifications

You’re not receiving notifications from this thread.

eval issue in Rails view

1
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.

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.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.