mercredi 6 mai 2015

ActiveRecord::RecordNotFound in AffinitiesController#index

When I try to access http://localhost:3000/affinities, I get the error in the title. Below it reads 'Couldn't find Affinity without an ID'.

Here is my 'affinities_controller.rb':

class AffinitiesController < InheritedResources::Base
def index
    @affinities = Affinity.all
end

def new
    @affinity = Affinity.new
end

def create
    @affinity = Affinity.new(params[:affinity])

    if @affinity.save
        redirect_to @affinity
    else
        render 'new'
    end
end

def show
    @affinity = Affinity.find(params[:id])
end

def edit
    @affinity = Affinity.find(params[:id])
end

def update
@affinity = Affinity.find(params[:id])

debugger
    @affinity.update_attributes(params[:affinities])
    @affinity.save
    redirect_to @affinity
end

def destroy
    @affinity = Affinity.find(params[:id])
    @affinity.destroy

    redirect_to affinity_index_path
end

The error is caused by the index method. Here is the view for index:

%h3 Affinities
=link_to 'New Affinity', new_affinity_path
<br><br>

%h3 Listing Affinities
%table
    - @affinities.each do |affinity|
        %tr
            %td=affinity.profile_affinity
            %td=affinity.tip_affinity
            %td=link_to 'Show', affinity_path(affinity)
            %td=link_to 'Edit', edit_affinity_path(affinity)
            %td=link_to 'Delete', affinity_path(affinity), :method => :delete, data: { confirm: 'Are you sure?' }

And here are my routes:

Sxs::Application.routes.draw do
resources :prediction_configs

resources :affinities

#----------------------------------------------------------------#
...

What could be wrong?

Aucun commentaire:

Enregistrer un commentaire