Reputation: 329
Is there a way I can clean up my views when it comes to an example below like user links? I remember reading in a book remove if and else statements put it into a controller or something. Can't find it at the moment.
<% if current_user %>
<%= link_to edit_post_path(blog) do %>
<i class="fas fa-edit"></i> Edit Post
<% end %>
<%= link_to blog_post_index do %>
<i class="fas fa-trash"></i> Delete Post
<% end %>
<% end %>
Upvotes: 0
Views: 490
Reputation: 198
Or make a shared folder and put the code in a template.
Like: app > views > shared > links > _user_link.html
Then call in your views:
= render "shared/links/user_link"
You can also parse extra info like:
= render "shared/links/user_link", f: f
Upvotes: 0
Reputation: 818
You can use rails view helpers for such code.
See..
https://api.rubyonrails.org/classes/ActionController/Helpers.html
Upvotes: 2