Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. <li><%= link_to "Company", company_path, :method => :get %></li>
  2.  
  3. No route matches {:action=>"show", :controller=>"companies"} missing required keys: [:id]
  4.  
  5. def current_company
  6. @company = Company.find_by_id(params[:id])
  7. end
  8.  
  9. <%unless current_page?(root_path)||current_page?(companies_path)||current_company.nil? %>
  10.  
  11. <li><%= link_to "Company", company_path, :method => :get %></li>
  12.  
  13. before_action :set_company, only: [:show, :edit, :update, :destroy, :company_home]
  14.  
  15. def company_home
  16. current_company = @company
  17. respond_with(@company)
  18. end
  19.  
  20. def current_company=(company)
  21. session[:current_company] = company.id
  22. puts "The current_company has been assigned"
  23. puts params.inspect
  24. end
  25.  
  26. def current_company
  27. @company = Company.find_by_id(session[:current_company])
  28. puts "The current_company helper has been called"
  29. puts @company
  30. puts params.inspect
  31. end
  32.  
  33. def company_home
  34. puts "Test the current company"
  35. puts "#{@company.id} #{@company.name}"
  36. puts params.inspect
  37. end
  38.  
  39. private
  40. def set_company
  41. @company = Company.find_by_id(params[:id])
  42. if @company.nil?||current_user.organisation_id != @company.organisation.id
  43. flash[:alert] = "Stop poking around you nosey parker"
  44. redirect_to root_path
  45. else
  46. current_company = @company
  47. end
  48. end
  49.  
  50. Started GET "/company_home/1" for 80.55.210.105 at 2014-12-19 10:26:49 +0000
  51. Processing by CompaniesController#company_home as HTML
  52. Parameters: {"authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "id"=>"1"}
  53. User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 6 ORDER BY "users"."id" ASC LIMIT 1
  54. Company Load (0.3ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 1 LIMIT 1
  55. Organisation Load (0.3ms) SELECT "organisations".* FROM "organisations" WHERE "organisations"."id" = $1 LIMIT 1 [["id", 6]]
  56. Test the current company
  57. 1 Cine
  58. {"_method"=>"get", "authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "controller"=>"companies", "action"=>"company_home", "id"=>"1"}
  59. Rendered companies/company_home.html.erb within layouts/application (0.1ms)
  60. Company Load (0.6ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" IS NULL LIMIT 1
  61. The current_company helper has been called
  62.  
  63. {"_method"=>"get", "authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "controller"=>"companies", "action"=>"company_home", "id"=>"1"}
  64. CACHE (0.0ms) SELECT "organisations".* FROM "organisations" WHERE "organisations"."id" = $1 LIMIT 1 [["id", 6]]
  65. Completed 200 OK in 280ms (Views: 274.0ms | ActiveRecord: 1.7ms)
  66.  
  67. def current_company=(company)
  68. session[:company_id]=company.id
  69. end
  70.  
  71. def current_company
  72. Company.find_by_id(session[:company_id])
  73. end
  74.  
  75. def show
  76. # assuming you have a before_action, something like set_company, no need to redo it
  77. current_company=@company # this will set the session variable
  78. end
  79.  
  80. <% unless current_company.nil? %>
  81. <li><%= link_to "Company", current_company, :method => :get %></li>
  82. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement