Question

I'm using Rails 4 and seem to be encountering what I've found on StackOverflow to be the common "dot route" error. However, it doesn't seem to be caused from a pluralization error, and I'm too new to Rails to understand why it would be happening. Here's the routing along with the output of rake routes:

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

However, when I do the following:

<% @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 %>

I end up getting http://localhost:3000/current_board.1 etc. for the paths.

Was it helpful?

Solution 2

Use real builtin routing, much easier to extend and maintain:

 resources :current_board, controller: :board_members, only: [:index, :show]

OTHER TIPS

first of all you should use

get '/current_board', to: 'board_members#index', :as => 'current_boards'
get '/current_board/:id', to: 'board_members#show', :as => 'current_board'

That makes it easier do address the route. but it's ugly.

and for using an "a" use the link_to helper with an block

<%= link_to current_board_path( board_member ) do %>
  <%= 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>
<% end %>

it should work. give it a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top