ruby-on-rails - 将变量放入 Rails 部分
问题描述
只是一个简单的问题,我是 Rails 上的新蜜蜂,我想知道如何在 Rails 中使用 partials,比如我们如何与 react 中的组件交互,而 rails 只是一个简单的例子。
下面是我尝试过的代码。我想渲染自定义导航栏
<% @nav_links = ['hello','welcome','sign up']
@showDropdown = false
@isAuth = false
%>
<%= render 'shared/navlinks' , locals: {nav_links: @nav_links, showDropdown: @showDropdown , isAuth: @isAuth } %>```
I tried the above code to pass the variables into a partial but is there a way like the below
```rubyonrails
<%= render 'shared/navlinks' ,
locals: {nav_links: ['hello','welcome','sign up'],
showDropdown: false ,
isAuth: false } %>```
I am getting `undefined local variable or method` I feel like I am missing something here is this how the instance variable works in ruby
? Any suggestion is much appreciated... Thank you
解决方案
只需替换为
<%= render partial: 'shared/navlinks' , locals: {nav_links: ['hello', 'welcome', 'signup'], showDropdown: false, isAuth: false } %>
无需设置成变量
推荐阅读
- sql - 如何在select语句vb.net中定义变量?
- python - 动态创建可以附加附加值的字典键?
- python - 熊猫 Excel Writer 无法正常工作
- python - 如何添加多个具有固定值的新列?
- google-sheets - 如果 Google 表格查询与另一张表格上的列中的任何值匹配,则返回所有行
- javascript - 无法在 D3.js 中填充折线图中的线
- react-native - react-navigation 3 在嵌套堆栈中重置
- java - N-Queens 不打印所有解决方案
- sql-server - 自动生成的外键数据库
- c - C 语言:Switch case 奇怪的例子不以“;”结尾 也不“断”