我使用Rails 4,似乎遇到了我在StackOverflow上發現的常見「點路由」錯誤。但是,它似乎並不是由於多元化錯誤導致的,而且我對Rails也不太瞭解它爲何會發生。下面是與rake routes
輸出沿着路由:Rails Path Helper生成Dot Route而不是Slash
match '/current_board', to: 'board_members#index', via: 'get'
match '/current_board/:id', to: 'board_members#show', via: 'get'
Prefix Verb URI Pattern Controller#Action
board_members GET /board_members(.:format) board_members#index
POST /board_members(.:format) board_members#create
new_board_member GET /board_members/new(.:format) board_members#new
edit_board_member GET /board_members/:id/edit(.:format) board_members#edit
board_member GET /board_members/:id(.:format) board_members#show
PATCH /board_members/:id(.:format) board_members#update
PUT /board_members/:id(.:format) board_members#update
DELETE /board_members/:id(.:format) board_members#destroy
current_board GET /current_board(.:format) board_members#index
GET /current_board/:id(.:format) board_members#show
然而,當我做到以下幾點:
<% @board_members[0..5].each do |board_member| %>
<div class="col-xs-4 col-md-2">
<a href="<%= current_board_path(board_member) %>">
<%= image_tag(board_member.photo_url, alt: "Photo of #{board_member.name}", class: 'center-block board-thumbnail img-rounded') %>
<div class="caption">
<h4 class="text-center"><%= board_member.name %></h4>
<p class="text-center"><%= board_member.position %></p>
</div>
</a>
</div>
<% end %>
我最終得到http://localhost:3000/current_board.1
等的路徑。
這個工作完美,比其他解決方案更清潔。一個警告是我現在必須使用'current_board_index_path'而不是'current_board_path'作爲'index',但它的工作原理!謝謝! – sethfri