-2

Just a quick question I am a new bee on rails I am wondering how to work with partials in rails like how we interact with components in react and rails just a quick example.

Below is the code I have tried. I want to render custom navbar

<% @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

1 Answers1

0

Just replace with

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

no need to set into variable

Kamal Pandey
  • 1,508
  • 1
  • 8
  • 12