2014-09-23 31 views
0

的Ruby on Rails應用程序有兩種模式用戶和位置user_path關聯不工作

用戶模型

belongs_to :location 

選址模型

has_many :users 

的routes.rb

devise_for :users 
resources :users 

這個位置的視圖ñ顯示頁面

<% @location.users.each do |locuser| %> 
    <%= link_to locuser.email, user_path %><br>  
<% end %> 

錯誤是無法與 'ID'

這是我的用戶控制器

def show 
@user = User.find(params[:id]) 
end 

我加入<%= link_to locuser.email, current_user %> 還沒有找到工作的用戶。

回答

1

我在考慮你沒有使用設計路線。不需要將用戶對象傳遞給路由。在你的show動作中,你確實需要id,所以我傳遞了顯示路徑的用戶對象。如果不運行的情況下rake routes | grep user和粘貼登錄這裏

應該user_path(locuser)

嘗試改變:

<% @location.users.each do |locuser| %> 
    <%= link_to locuser.email, user_path(locuser) %><br>  
<% end %> 

<% @location.users.each do |locuser| %> 
    <%= link_to locuser.email, locuser %><br>  
<% end %>