title: ROR: Creating a method with a parameter
body: <p>I have an admins dashboard which displays posts created in the last 24 hours, 7 days, 28 days etc.</p>
  
  <pre><code>def index
    @1DayPosts = Post.where(created_at: 1.days.ago..DateTime.now).count 
    @7DaysPosts = Post.where(created_at: 7.days.ago..DateTime.now).count 
    @28DaysPosts = Post.where(created_at: 28.days.ago..DateTime.now).count 
  end
  </code></pre>
  
  <p>How could I make this into one line? Something like the below:</p>
  
  <pre><code>def index
    @calculatePosts(a) = Post.where(created_at: a.days.ago..DateTime.now).count 
  end
  </code></pre>
  
  <p>Then in the view I could do:</p>
  
  <pre><code>=@calculatePosts(1)
  </code></pre>
  
  <p>Or would I need to create a new method?</p>
  
  <pre><code>def calculatePosts(a)
      @calculatePost = Post.where(created_at: a.days.ago..DateTime.now).count
  end
  </code></pre>
  
  <p>How would I then call this in the index view?</p>