AffinitiesController #index中的ActiveRecord :: RecordNotFound

时间:2015-05-07 01:33:00

标签: ruby-on-rails ruby ruby-on-rails-3 activerecord localhost

当我尝试访问http://localhost:3000/affinities时,我在标题中收到错误。下面的内容是“如果没有ID,就无法找到亲和力”。

这是我的' 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

错误是由索引方法引起的。以下是索引的视图:

%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?' }

这是我的路线:

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

resources :affinities

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

可能出现什么问题?

0 个答案:

没有答案