I'm new to ruby and now I have the following problem: I installed the datagrid gem and created a grid which scopes my User model. I also added a Actions-Column in the grid to edit each user. When I click the edit-link I get an error saying "Couldn't find User without an ID" refering to the users\_controller.

users\_grid.rb:

```
class UsersGrid

include Datagrid

scope do
  User
end

filter(:id, :integer, :header => "test")
filter(:created_at, :date, :range => true)

column(:id)
column(:username)
column(:forename)
column(:lastname)
column(:email) do |model|
  format(model.email) do |value|
    link_to value, "mailto:#{value}"
  end
end
column(:created_at) do |model|
  model.created_at.to_date
end
column(:actions, :html => true) do |record|
  link_to "Edit", edit_path
end
end

```

users\_controller.rb:

```
class UsersController < ApplicationController

  before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
  before_action :correct_user,   only: [:edit, :update]

  def show
    @user = User.find(params[:id])
  end

  def new
     @user = User.new
  end

  def index
    @users = User.paginate(page: params[:page])
    @grid = UsersGrid.new(params[:users_grid])
    @assets = @grid.assets.paginate(:page => params[:page], :per_page => 15)
  end

  def create
    @user = User.new(user_params)
    if @user.save
      login @user
      flash[:success] = "User created successfully!"
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(user_params)
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end

  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User deleted."
    redirect_to users_url
  end

  private

    def user_params
      params.require(:user).permit(:username, :forename, :lastname, :email, :password,
                               :password_confirmation)
    end

    # Before filters

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_url) unless current_user?(@user)
    end
end

```

routes.rb:

```
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :dashboards, only: [:index]
root  'dashboards#operation'
match '/index', to: 'users#index', via: 'get'
match '/edit', to: 'users#edit', via: 'get'
match '/login', to: 'sessions#new', via: 'get'
match '/logout', to: 'sessions#destroy', via: 'delete'
match '/operation',  to: 'dashboards#operation', via: 'get'

```

error message:

> 
> Couldn't find User without an ID
> 
> 
> 

related code in users\_controller:

```
def correct_user
  @user = User.find(params[:id])
  redirect_to(root_url) unless current_user?(@user)
end 

```

Thank you for any help... my knowledge is too limited in ruby.