Loganhinter
Loganhinter

Reputation: 67

Accessing controller from header partial

I thought this would be easier to do but I haven't been able to find a solution. Basically I want my layouts/_header.html.erb file to have access to a notifications method in my users controller or even just create a new method for this partial if that's possible.

layouts/_header.html.erb:

<% if @posts_count > 0 %>
Hello
<% end %>

users_controller.rb:

def notifications
@posts_count = @reminder.posts.count
end

The header is being rendered in

application.html.erb:

<%= render 'layouts/header' %>

Upvotes: 0

Views: 41

Answers (1)

Puhlze
Puhlze

Reputation: 2614

It sounds like you want to declare that method as a helper method in your controller.

In your controller try adding:

helper_method :notifications

Here's the doc: http://apidock.com/rails/ActionController/Helpers/ClassMethods/helper_method

Upvotes: 1

Related Questions