我正在使用lists
构建基本的类型应用,其中每个has_many
items
。我正在尝试为委派任务(sharing/tasks.html.erb
)构建一个视图,以显示已标记为委派的items
。以下是tasks.html.erb
页面上的相关代码:
<h2 class="text-center">Delegated to Me</h2>
<% @deligated_to_me.each do |item| %>
<p><%= link_to list_path(@list) do %>
<%= item.name %>
<% end %>
(Deligated by <%= item.user_id %>)</p>
<% end %>
以下是sharing_controller
页面的tasks
部分:
def tasks
@lists = List.all
@list = List.friendly.find(params[:list_id]) <<<<ERROR CALLED ON THIS LINE
@items = Item.all
@delegated_to_me = @items.where(:delegated_to == current_user.email)
@delegated_by_me = current_user.items.where.not(delegated_to: "")
end
当我尝试查看该页面时,我收到Record Not Found
错误Couldn't find List without an ID
。从我在其他SO帖子上看到的情况来看,通常这是一个未在控制器中声明的变量的问题,但这似乎不是这里的情况。任何人都可以帮我排除故障吗?
附加信息:路线
list_items GET /lists/:list_id/items(.:format) items#index
POST /lists/:list_id/items(.:format) items#create
new_list_item GET /lists/:list_id/items/new(.:format) items#new
edit_list_item GET /lists/:list_id/items/:id/edit(.:format) items#edit
list_item GET /lists/:list_id/items/:id(.:format) items#show
PATCH /lists/:list_id/items/:id(.:format) items#update
PUT /lists/:list_id/items/:id(.:format) items#update
DELETE /lists/:list_id/items/:id(.:format) items#destroy
lists GET /lists(.:format) lists#index
POST /lists(.:format) lists#create
new_list GET /lists/new(.:format) lists#new
edit_list GET /lists/:id/edit(.:format) lists#edit
list GET /lists/:id(.:format) lists#show
PATCH /lists/:id(.:format) lists#update
PUT /lists/:id(.:format) lists#update
DELETE /lists/:id(.:format) lists#destroy
sharing_lists GET /sharing/lists(.:format) sharing#lists
sharing_tasks GET /sharing/tasks(.:format) sharing#tasks
答案 0 :(得分:0)
将@list替换为item.list
<h2 class="text-center">Delegated to Me</h2>
<% @deligated_to_me.each do |item| %>
<p>
<%= link_to list_path(item.list) do %>
<%= item.name %>
<% end %>
(Deligated by <%= item.user_id %>)
</p>
<% end %>
并从控制器中删除代码。
@list = List.friendly.find(params[:list_id])