2013-11-25 22 views
0

我用西班牙語製作了所有模型名稱的應用程序。我遇到一些與單數化有關的奇怪問題。 我的模型:顯示視圖的奇怪路由行爲

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 

(所有這一切都已經自動與軌道創建生成命令)

現在,我的路線包括以下內容:

resources :artistas 

當我訪問localhost:3000/artistas一切效果很好。我可以看到已經創建的aritsts列表。現在,當我點擊一位現有的藝術家(或者在我嘗試創建一個新的藝術家後,被重定向到藝術家頁面),出於某種奇怪的原因,它會轉到http://localhost:3000/artistum.3(3是我點擊的藝術家的標識)。該網址的輸出是完全空白的頁面。

我甚至從來沒有輸入過藝術家這個詞。我不知道它從哪裏得到。此外,它有一個點而不是斜線來分隔名稱,所以我不知道如何重定向它。

我運行了包含所有內容的文件夾的grep搜索,並且只有在日誌文件中存在artistum字樣。

我的猜測是,我的應用程序的某些部分認爲「artista」是複數,「artistum」是它的單數形式。

我加入了我的路線match '/artistum' => 'artistas#index',它適用於索引頁面,但是這個點讓我很困惑如何爲展示頁面做到這一點。

有人可以幫助我A)找出爲什麼試圖到達那裏或b)如何從這些展示頁面路由? 謝謝!

+0

如何爲用戶點擊每個單獨的''link_to' Artista'是什麼樣子? –

回答

2

你可以試試這個:

config/initializers文件夾此爲inflections.rb地址:

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.plural 'artista', 'artistas' 
    inflect.irregular 'artista', 'artistas' 
end