Rails partial - 来自变量的局部变量名?

时间:2020-12-09 16:47:40

I currently have some code to render a partial, which includes:

我目前有一些代码来渲染部分代码,其中包括:

:locals => {:feature => y}

This works fine, but I would like to be able to use a variable in place of :feature - I have tried the following:

这工作正常,但我希望能够使用变量代替:feature - 我尝试过以下方法:

:locals => {type.singularize => y}

but to no avail. What is the correct syntax to replace :feature with a local variable?

但无济于事。要替换的正确语法是什么:使用局部变量的功能?

Thanks!

谢谢!

1 个解决方案

#1


1  

Incase anyone else comes across this, I was able to resolve it using the code in the comments from apneadiving and MurifoX:

如果其他任何人遇到此问题,我可以使用apneadiving和MurifoX的评论中的代码解决它:

:locals => {type.singularize.to_sym => y}

#1


1  

Incase anyone else comes across this, I was able to resolve it using the code in the comments from apneadiving and MurifoX:

如果其他任何人遇到此问题,我可以使用apneadiving和MurifoX的评论中的代码解决它:

:locals => {type.singularize.to_sym => y}