ActionController::UrlGenerationError 在搜索中#search

ActionController::UrlGenerationError in Search#search

我已经安装了 ElasticSearch,但我用这个无法搜索:

<%= link_to genre_linker.genre, movie_genre_linker_path(@movie, genre_linker) %>

但是当我使用这个时结果显示正确:

<%= link_to genre_linker.genre %>

所以,由于搜索有效,我认为问题出在我的语法中。

这是我的路线:

movie_genre_linker GET    /movies/:movie_id/genre_linkers/:id(.:format)         genre_linkers#show 

这是错误信息:

我还是个菜鸟,所以非常感谢任何指导。

movies_controller.rb

class MoviesController < ApplicationController
  before_action :set_movie, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]


  def index
    @movies = Movie.all
  end


  def show
    @genre_linkers = GenreLinker.where(movie_id: @movie.id).order("created_at DESC")
     @common_linkers = CommonLinker.where(movie_id: @movie.id).order("created_at DESC")
    @theme_linkers = ThemeLinker.where(movie_id: @movie.id).order("created_at DESC")
     @location_linkers = LocationLinker.where(movie_id: @movie.id).order("created_at DESC")
  end


  def new
     @movie = current_user.movies.build
  end


  def edit
  end

  def create
    @movie = current_user.movies.build(movie_params)

    respond_to do |format|
      if @movie.save
        format.html { redirect_to @movie, notice: 'Movie was successfully created.' }
        format.json { render :show, status: :created, location: @movie }
      else
        format.html { render :new }
        format.json { render json: @movie.errors, status: :unprocessable_entity }
      end
    end
  end


  def update
    respond_to do |format|
      if @movie.update(movie_params)
        format.html { redirect_to @movie, notice: 'Movie was successfully updated.' }
        format.json { render :show, status: :ok, location: @movie }
      else
        format.html { render :edit }
        format.json { render json: @movie.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @movie.destroy
    respond_to do |format|
      format.html { redirect_to movies_url, notice: 'Movie was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private

    def set_movie
      @movie = Movie.find(params[:id])
    end

    def movie_params
       params.require(:movie).permit(:title, :description, :movie_length, :poster)
    end
end

genre_linkers_controller.rb

class GenreLinkersController < ApplicationController
  before_action :set_genre_linker, only: [:show, :edit, :update, :destroy, :votes]
  before_action :set_movie
  before_action :authenticate_user!, except: [:index, :show]
  respond_to :html

  def index
    @genre_linkers = GenreLinker.all
    respond_with(@genre_linkers)
  end

  def show
    @genre_linker = GenreLinker.find(params[:id])
  end

   def vote
      value = params[:type] == "up" ? 1 : -1
      @genre_linker = GenreLinker.find(params[:id])
     @genre_linker.add_or_update_evaluation(:votes, value, current_user)
      redirect_to :back, notice: "thanks for the vote"
   end


  def new
    @genre_linker = GenreLinker.new
    respond_with(@genre_linker)
  end

  def edit
  end

  def create
     @genre_linker = GenreLinker.new(genre_linker_params)
     @genre_linker.user_id = current_user.id
     @genre_linker.movie_id = @movie.id

     if @genre_linker.save
        redirect_to @movie
    else
      render 'new'
    end
  end

  def update
    @genre_linker.update(genre_linker_params)
    respond_with(@genre_linker)
  end

  def destroy
    @genre_linker.destroy
    respond_with(@genre_linker)
  end

  private
    def set_genre_linker
      @genre_linker = GenreLinker.find(params[:id])
    end

   def set_movie
      @movie = Movie.find(params[:movie_id])
   end

    def genre_linker_params
       params.require(:genre_linker).permit(:genre, :description)
    end
end

search/search.html.erb

<%= form_for search_path, method: :get do |f| %>
  <p>
    <%= f.label "Search for" %>
    <%= text_field_tag :q, params[:q] %>
    <%= submit_tag "Go", name: nil %>
  </p>
<% end %>

<ul>
  <% @genre_linkers.each do |genre_linker| %>
    <li>
      <%= link_to genre_linker.genre, movie_genre_linker_path(@movie, genre_linker) %>


    </li>

</ul
    <% end %>

search_controller.rb

class SearchController < ApplicationController
  def search
  if params[:q].nil?
    @genre_linkers = []
  else
    @genre_linkers = GenreLinker.search params[:q]
  end
end

end

这有效: <%= link_to genre_linker.genre, movie_path(genre_linker.movie.id) %>