一个简单的问题,我是Rails上的一只新蜜蜂,我想知道如何使用Rails中的局部对象,例如我们如何与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
答案 0 :(得分:0)
只需替换为
<%= render partial: 'shared/navlinks' , locals: {nav_links: ['hello', 'welcome', 'signup'], showDropdown: false, isAuth: false } %>
无需设置为变量