title: Implementing datagrid gem & session helper methods
body: <p>I'm a newbie trying to implement the <code>datagrid gem</code> (<a href="https://github.com/bogdan/datagrid" rel="nofollow">https://github.com/bogdan/datagrid</a>). Unfortunately, I'm getting three error messages:</p>
  
  <pre><code>Error 1: undefined method 'filter' for #&lt;UsersGrid:0x000000044e9400&gt;
  Referring to: line `@grid.filter` in def index
  
  Error 2: undefined local variable or method 'user' for #&lt;UsersController:0x007f821f434808&gt;
  Referring to: line `link_to view_context.image_tag("delete.gif",...` in the controller.
  
  Error 3: undefined method `image_tag' for UsersGrid:Class
  Referring to: line `link_to image_tag(user.avatar.url,` in users_grid.rb
  Placing `view_context` in front of link_to in users_grid.rb doesn't work either: undefined local variable or method 'view_context' for UsersGrid:Class.
  Also tried `ActionController::Base.helpers.image_tag`. Although that seems to solve the image_tag issue, I then get the error message: `undefined method 'user_path' for #&lt;ActionView::Base:0x007f821d3115b8&gt;` referring to that same line.
  </code></pre>
  
  <p>Removing all the lines above, and the form works :-)</p>
  
  <p>Any suggestions how to change the code below to adjust for these errors?</p>
  
  <hr>
  
  <p><strong>My code:</strong> After installing the gem I have created /app/grids/users_grid.rb:</p>
  
  <pre><code>class UsersGrid
    include Datagrid
  
    scope do
      User.order("users.created_at desc")
    end
  
    filter(:id, :integer)
    filter(:email, :string) { |value| where('email like ?', "%#{value}%") }
    filter(:organization, :string) { |value| where('organization like ?', "%#{value}%") }
    filter(:verified, :xboolean)
    filter(:created_at, :date, :range =&gt; true, :default =&gt; proc { [1.month.ago.to_date, Date.today]})
  
    column(:id)
    column(:avatar) do |user|
      if user.avatar?
        link_to image_tag(user.avatar.url, alt: "Profile"), user_path(user)       #Error3
      else
        link_to image_tag("profile.gif", alt: "Profile"), user_path(user)
      end
    end
    column(:organization)
    column(:verified) do |user|
      image_tag("verifiedaccount.gif", title: "verified") if user.verified
    end
    column(:created_at) do |model|
      model.created_at.to_date
    end
  end
  </code></pre>
  
  <p>The users controller:</p>
  
  <pre><code>def index
    @grid = UsersGrid.new(params[:users_grid]) do |scope|
      scope.where(admin: false).page(params[:page]).per_page(30)
    end
    @grid.assets
    if (current_user &amp;&amp; current_user.admin?)        # This is a Sessions helper method.
      @grid.filter(:activated, :xboolean, :default =&gt; true)                    #Error1
      @grid.column(:myadmin, :header =&gt; "My admin?") do |user|
        view_context.image_tag("adminamina.png", title: "admin") if user.myadmin
      end
      @grid.column(:activated) do |user|
        user.activated_at.strftime('%v') if user.activated
      end
      @grid.column(:remove) do |user|
        link_to view_context.image_tag("delete.gif", title: "remove"), user, method: :delete,
                                      data: { confirm: "Please confirm" }       #Error2
      end
    end
  end
  </code></pre>
  
  <p>The view:</p>
  
  <pre><code>&lt;%= datagrid_form_for @grid, :method =&gt; :get, :url =&gt; users_path %&gt;
  &lt;%= will_paginate(@grid.assets) %&gt;
  &lt;%= datagrid_table(@grid) %&gt;
  &lt;%= will_paginate(@grid.assets) %&gt;
  </code></pre>