0

我的提交者模型中的记录显示在应用程序索引视图中,显示在如下表中。只有我希望能够单击为 列出的号码.count()并被带到我的门票索引视图,其中列出了所有相应的记录(门票)。

我无法理解如何将实例变量链接到控制器的操作,以便使用我的视图布局。

有任何想法吗?

<table>
  <tr>
    <th>Name</th>
    <th>Number of Tickets</th>
  </th>
  <tr>
    <% Submitter.where(:school_id => current_user.school_id, :disabled => false).each do |sub| %>
    <td><%= link_to sub.full_name, edit_submitter_path(sub) %></td>
    <td><%= Ticket.where(:submitter_id => sub).count %></td>
  </tr>
    <% end %>
</table>

路线.rb

resources :feedbacks
resources :products

get "password_resets/new"
get 'signup', to: 'users#new', as: 'signup'
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'

resources :users
resources :sessions
resources :password_resets
resources :mailing_lists
resources :submitters
resources :emails
resources :notes
resources :reminders
resources :descriptions
resources :issues
resources :locations
resources :schools
resources :tickets

root :to => "application#index"
4

2 回答 2

1

听起来您的提交者有很多票。如果是这样,您将显示提交者列表(在 submitters_controller#index 方法中)并计算票证的数量。然后将该号码链接到 ticket_controller#index 方法。像这样...

路线.rb

resources :submitters do
  resources :tickets
end

submitters_controller.rb

class SubmittersController < ApplicationController

  def index
    @submitters = Submitter.where(:school_id => current_user.school_id, :disabled => false)
  end

end

门票控制器.rb

class TicketsController < ApplicationController

  def index
    @submitter = Submitter.find(params[:submitter_id])
    @tickets = @submitter.tickets
  end

end

意见/提交者/index.html.erb

<table>
  <tr>
    <th>Name</th>
    <th>Number of Tickets</th>
  </th>
  <% @submitters.each do |sub| %>
    <tr>
      <td><%= link_to sub.full_name, edit_submitter_path(sub) %></td>
      <td><%= link_to pluralize(sub.tickets.count, 'ticket'), submitter_tickets_path(sub) %></td>
    </tr>
  <% end %>
</table>

意见/票/index.html.erb

# This would show a list of tickets and their attributes - possibly linking to a ticket.
于 2013-10-09T02:30:03.987 回答
0

可能是这样的?不是 100% 理解你的问题。

<table>
  <tr>
    <th>Name</th>
    <th>Number of Tickets</th>
  </th>
  <tr>
    <% Submitter.where(:school_id => current_user.school_id, :disabled => false).each do |sub| %>
      <td><%= link_to sub.full_name, edit_submitter_path(sub) %></td>
      <td><%= link_to pluralize(sub.tickets.count, 'ticket'), tickets_path %></td>
    <% end %>
  </tr>
</table>

config/routes.rb当然,除非我知道你的样子,否则我不能给你完美的工作代码,因为我不知道你的门票索引视图的方法是什么。

于 2013-10-09T02:13:56.723 回答