显示视图的奇怪路线行为

时间:2013-11-25 04:15:34

标签: ruby-on-rails ruby ruby-on-rails-3 routes pluralize

我正在用西班牙语制作一个包含所有模型名称的应用程序。我有一些与单一化有关的奇怪问题。 我的模特:

class Artista < ActiveRecord::Base
  attr_accessible :fecha, :foto, :instrumento, :nombre
end

我的模特名字是“artista”(艺术家)的单数。

控制器:

class ArtistasController < ApplicationController
  # GET /bandas
  # GET /bandas.json
  def index
    @artistas = Artista.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @artistas }
    end 
  end 

  def show
    @artista = Artista.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @artista }
    end 
  end 
  def new
    @artista = Artista.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @artista }
    end
  end

  def edit
    @artista = Artista.find(params[:id])
  end

  def create
    @artista = Artista.new(params[:artista])

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

  def update
    @artista = Artista.find(params[:id])
    respond_to do |format|
      if @artista.update_attributes(params[:banda])
        format.html { redirect_to @artista, notice: 'Artista was successfully updated.' }
        format.json { head :no_content }
 else
        format.html { render action: "edit" }
        format.json { render json: @artista.errors, status: :unprocessable_entity }
      end
    end
 end
  def destroy
    @artista = Artista.find(params[:id])
    @artista.destroy
    respond_to do |format|
      format.html { redirect_to artistas_url }
      format.json { head :no_content }
    end
   end
   end

(所有这些都是使用rails generate命令自动创建的)

现在,我的路线包括以下内容:

resources :artistas

当我访问localhost:3000/artistas时,一切都很有效。我可以看到已经创建的aritst列表。现在,当我点击一个现有的艺术家时(或者在我尝试创建一个新艺术家之后,被重定向到显示艺术家页面)出于某种奇怪的原因,它会转到http://localhost:3000/artistum.3(3是我点击的艺术家的ID上)。该网址的输出是一个完全空白的页面。

我甚至从未输入artum这个词。我不知道从哪里得到它。此外,它有一个点而不是斜杠来将名称与id分开,所以我不知道如何重定向它。

我对包含所有内容的文件夹进行了grep搜索,而artum这个词只存在于日志文件中。

我的猜测是,我的应用程序的某些部分认为“artista”是复数,“artistum”是它的单数形式。

我添加到我的路线match '/artistum' => 'artistas#index',这适用于索引页面,但是点让我对如何为节目页面这样做感到困惑。

有人可以帮助我吗A)找出它为什么要到达那里或b)如何从这些节目页面路由? 谢谢!

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

将其添加到inflections.rb文件夹中的config/initializers

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'artista', 'artistas'
  inflect.irregular 'artista', 'artistas'
end
相关问题