未定义方法“to_model”ActiveRecord 关系

0 activerecord ruby-on-rails ruby-on-rails-5

我有这个确切的错误消息:undefined method to_model\' for #<Onduleur::ActiveRecord_Relation:0x007f8bcf631110>

\n\n

我错过了一些东西......但是什么?\n感谢您的帮助:)

\n\n

这是views/installations/_form.html.erb中的搜索表单

\n\n
<%= simple_form_for :query, url: @onduleurs, method: :get, wrapper: :inline_form, html: {class: \'form-inline\'} do |f| %>\n  <%= f.input :identifier, collection: Onduleur.group(:identifier).map {|o| o.identifier} ,  prompt: "Choississez un onduleur" %>\n  <%= f.button :submit, "Chercher", class:"btn btn-success" %>\n  <%= link_to "Voir tous les onduleurs", {controller: "installations", action: \'show\'}, class: "btn btn-success"  %>\n<% end %>\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的Installations_controller.rb

\n\n
 class InstallationsController < ApplicationController\n\n  def index\n    @installations = Installation.all\n  end\n\n  def show\n    filter_onduleurs if params[:query].present?\n    @onduleurs ||= Onduleur.all\n    @installation = Installation.find(params[:id])\n  end\n\n  def new\n    @installation = Installation.new\n  end\n\n  def create\n    @installation = Installation.new(installation_params)\n    if @installation.save\n      redirect_to installations_path, notice: "L\'installation a bien \xc3\xa9t\xc3\xa9 cr\xc3\xa9e"\n    else\n      render :new, notice: "L\'installation n\'a pas pu \xc3\xaatre cr\xc3\xa9e, veuillez r\xc3\xa9\xc3\xa9ssayer"\n    end\n  end\n\n\n  private\n\n  def filter_onduleurs\n    @onduleurs = Onduleur.where(\'identifier LIKE ?\', params[:query][:identifier]) if params[:query][:identifier].present?\n    @onduleurs = Onduleur.where(\'datetime LIKE ?\', params[:query][:datetime]) if params[:query][:datetime].present?\n  end\n\n  def installation_params\n    params.require(:installation).permit(:name)\n  end\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n

关于我的模型:

\n\n

安装.rb

\n\n
has_many :onduleurs,  dependent: :destroy\n
Run Code Online (Sandbox Code Playgroud)\n\n

onduleur.rb

\n\n
belongs_to :installation\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的路线:

\n\n
 resources :installations do\n  resources :onduleurs do\n    collection {post :import}\n  end\nend\nroot to: "installations#index"\n
Run Code Online (Sandbox Code Playgroud)\n