2012-03-19 87 views
0

我有一個控制器和視圖(CTRLER)建立一個動態的軌道路線

控制器

def index 
     ... 
    end 

    def show 
     @text = params[:text]  
    end 

end 

視圖(show.html.erb)

<%[email protected] %> 

的routes.rb

resources :ctrler 

match 'ctrler/:text' => 'ctrler#show' 

如果我開火rails s服務器啓動並加載http://localhost:3000/ctrler/hiiiiiii我什麼也沒得到,但是如果我加載http://localhost:3000/ctrler?text=hiiiiii我得到文本!

我仍然試圖得到鐵路的hang I我習慣了PHP,但有人可以給我一些指導,我在正確的軌道上,或者我錯過了什麼嗎?

回答

2
resources :ctrler 

創建以下規則

match "ctrler/:id" => "ctrler#show" 

match 'ctrler/:text' => 'ctrler#show' 

這條路線的衝突在發生衝突的情況下,出現第一優先的規則,所以當你去' ctrlr/hiiiii',它將id參數設置爲hiiiii,而不是文本參數。嘗試將routes.rb更改爲

match 'ctrler/:text' => 'ctrler#show' 
resources :ctrler 

並查看是否有幫助。