参照/ユーザーを渡すときにすべての会社のリストを見たい
users_controller.rb:
def index
@companies = Company.all
respond_to do |format|
format.html # show.html.erb
format.json { render json: @companies }
end
end
users / index.html.haml:
%div{:style => "margin:10px" }
%table{ :class => "table table-striped"}
%thead
%tr
%th
= t("Logo")
%th
= t("company_name")
%th
= t("website")
%th
%tbody
- @companies.each do |company|
%tr
%td
- if company.logo?
= link_to image_tag( company.logo.url, :width => "60", :height => "60"), company
- else
= link_to image_tag( "/lg.png", :width => "60", :height => "60"), company
%td
= link_to company.name, company_path
%td
- if company.website?
= link_to company.website, company.website
- else
= link_to company.name, company_path
%td
- if can? :read, company
= link_to '<i class="icon-info-sign icon-white"></i> '.html_safe + t('Show'), company, :class => 'btn btn-small btn-info'
- if can? :update, company
= link_to '<i class="icon-pencil icon-white"></i> '.html_safe + t('Edit'), edit_company_path(company), :class => 'btn btn-small btn-pencil'
- if can? :destroy, company
= link_to '<i class="icon-trash icon-white"></i> '.html_safe + t('Destroy'), company, confirm: t('Are you sure'), method: :delete, :class => 'btn btn-small btn-danger'
ただし、リンクでエラーが発生した場合:
No route matches {:action=>"show", :controller=>"companies"}