Чтобы расширить ответ @mechnicov: внутри цикла используйте имя локальной переменной objective
, а не имя переменной экземпляра @objective
. NoMethodError
точно говорит вам, в чем проблема. Объект, для которого вы вызвали метод, равен nil, поскольку он не был определен.
Вот простой пример актуальной проблемы:
[:a, :b, :c].each { |item| print @item.capitalize }
# NoMethodError: undefined method `capitalize' for nil:NilClass
# the instance variable @item is an instance of NilCLass
[:a, :b, :c].each { |item| print item.capitalize }
# ABC=> [:a, :b, :c]
В rails вы определяете переменные экземпляра объекта модели внутри контроллера. Перебирая их в представлении, вы используете локальную переменную, назначенную в вашем цикле.
If you're using Visual Studio you can do the following.
This will get rid of the warning. The number 40000 is the VB.Net error number for the obselete warning. You can suppress any warning in this fashion.
Note: If the NoWarn tag is not present, add it to the main PropertyGroup element with the following values
<NoWarn>40000</NoWarn>
In VS.NET you can right click on and suppress code analysis warnings. This will add the attribute for you.
However, the "don't use obsolete APIs" warning is not coming from code analysis, and so the SurpressMessage attibute won't work. This is a compiler warning.
For VS.NET you'd need to switch off this warning with...
/nowarn:0618
... at the command line (or just adding "0618" into the Suppress Warnings field on the csproj properties). You should do the same with whatever the VB warning number is.