Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1

rails Routing Error in Rails 3.1


I want to see a list of all companies when pass by reference /users

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'

but when the link get the error:
No route matches {:action=>"show", :controller=>"companies"}


Solution

  • in your users_controller.rb' write

    def show
      respond_to do |format|
        format.html{}
        format.json{}
      end
    end
    

    and in your route file write

    resources :users