【问题标题】:getting variables into rails partials将变量放入 Rails 部分
【发布时间】:2019-10-24 05:12:27
【问题描述】:

只是一个简单的问题,我是 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

【问题讨论】:

    标签: ruby-on-rails partials


    【解决方案1】:

    只需替换为

     <%= render partial: 'shared/navlinks' , locals: {nav_links: ['hello', 'welcome', 'signup'], showDropdown: false, isAuth: false }  %>
    

    无需设置成变量

    【讨论】:

    • 好的 使用 partial: 会更容易吗?我认为这是我在顶部共享的代码中唯一缺少的部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    相关资源
    最近更新 更多