0

我正在使用西班牙语中的所有型号名称制作应用程序。我遇到了一些与奇异化相关的奇怪问题。我的模型:

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

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

控制器:

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一切都很好。我可以看到已经创建的艺术家列表。现在,当我出于某种奇怪的原因单击现有艺术家(或在我尝试创建新艺术家后,被重定向到表演艺术家页面后)时,它会转到http://localhost:3000/artistum.3(3 是我单击的艺术家的 id)。该 url 的输出是一个完全空白的页面。

我什至从来没有打过artistum这个词。我不知道它是从哪里弄来的。此外,它有一个点而不是斜线来分隔名称和 id,所以我不知道如何重定向它。

我对包含所有内容的文件夹进行了 grep 搜索,并且艺术家一词仅存在于日志文件中。

我的猜测是,我的应用程序的某些部分认为“艺术家”是复数形式,而“艺术家”是其单数形式。

我添加到我的路线match '/artistum' => 'artistas#index'并且适用于索引页面,但是这个点让我对如何为显示页面执行此操作感到困惑。

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

4

1 回答 1

2

你可以试试这个:

将此添加到inflections.rb文件config/initializers夹中:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'artista', 'artistas'
  inflect.irregular 'artista', 'artistas'
end
于 2013-11-25T04:24:37.667 回答