Trouble using RESTful helper


I am trying to get into this REST thing, I have a nested resource whith the following route:

ActionController::Routing::Routes.draw do |map|

  map.resources :members

  map.resources :clubs do |club|     club.resources :members   end

  map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format' end

Everything worked ok for this /clubs/#/members resource, but since I tried to use the REST url helpers, I get strange errors:

NoMethodError in Members#index

Showing members/index.html.erb where line #40 raised:

undefined method `has_key?' for #<Member:0x243ffd8>

Extracted source (around line #40):

37: <td><%= member.primary_telephone %></td> 38: <td><%= member.primary_mobile %></td> 39: 40: <td><%= link_to "Show", member_path(, member) %></td> 41: <td><%= link_to "Edit", edit_member_path(, member) %></td> 42: <td><%= button_to "Deactivate", member_path(, member), :method => :delete %></td> 43:

The index action of the controller is just:

  def index     @club = Club.find(params[:club_id])     @members = @club.members.find(:all, :conditions => ["is_active = ?",true])

    @term = get_term     respond_to do |format|       format.html # index.html.erb       format.xml { render :xml => @members }     end   end

I can use the same code from the console ok, so the models should be connected properly:

m = Member.find(:first)

=> #<Member id: 1, .....

=> #<Club id: 1, club_name: ...

What did I do wrong? Any ideas?


Fredrik Karlsson wrote:

40: <td><%= link_to "Show", member_path(, member) %></td

member_path() just expects to build /members/#. you want to use club_member_path(,


I guess you can't trust all things you read on the internet :slight_smile: