Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <li><%= link_to "Company", company_path, :method => :get %></li>
- No route matches {:action=>"show", :controller=>"companies"} missing required keys: [:id]
- def current_company
- @company = Company.find_by_id(params[:id])
- end
- <%unless current_page?(root_path)||current_page?(companies_path)||current_company.nil? %>
- <li><%= link_to "Company", company_path, :method => :get %></li>
- before_action :set_company, only: [:show, :edit, :update, :destroy, :company_home]
- def company_home
- current_company = @company
- respond_with(@company)
- end
- def current_company=(company)
- session[:current_company] = company.id
- puts "The current_company has been assigned"
- puts params.inspect
- end
- def current_company
- @company = Company.find_by_id(session[:current_company])
- puts "The current_company helper has been called"
- puts @company
- puts params.inspect
- end
- def company_home
- puts "Test the current company"
- puts "#{@company.id} #{@company.name}"
- puts params.inspect
- end
- private
- def set_company
- @company = Company.find_by_id(params[:id])
- if @company.nil?||current_user.organisation_id != @company.organisation.id
- flash[:alert] = "Stop poking around you nosey parker"
- redirect_to root_path
- else
- current_company = @company
- end
- end
- Started GET "/company_home/1" for 80.55.210.105 at 2014-12-19 10:26:49 +0000
- Processing by CompaniesController#company_home as HTML
- Parameters: {"authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "id"=>"1"}
- User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 6 ORDER BY "users"."id" ASC LIMIT 1
- Company Load (0.3ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 1 LIMIT 1
- Organisation Load (0.3ms) SELECT "organisations".* FROM "organisations" WHERE "organisations"."id" = $1 LIMIT 1 [["id", 6]]
- Test the current company
- 1 Cine
- {"_method"=>"get", "authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "controller"=>"companies", "action"=>"company_home", "id"=>"1"}
- Rendered companies/company_home.html.erb within layouts/application (0.1ms)
- Company Load (0.6ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" IS NULL LIMIT 1
- The current_company helper has been called
- {"_method"=>"get", "authenticity_token"=>"gfdhjfgjhoFFHGHGFHJGhjkdgkhjgdjhHGLKJGJHpDQs6yNjONwSyTrdgjhgdjgjf=", "controller"=>"companies", "action"=>"company_home", "id"=>"1"}
- CACHE (0.0ms) SELECT "organisations".* FROM "organisations" WHERE "organisations"."id" = $1 LIMIT 1 [["id", 6]]
- Completed 200 OK in 280ms (Views: 274.0ms | ActiveRecord: 1.7ms)
- def current_company=(company)
- session[:company_id]=company.id
- end
- def current_company
- Company.find_by_id(session[:company_id])
- end
- def show
- # assuming you have a before_action, something like set_company, no need to redo it
- current_company=@company # this will set the session variable
- end
- <% unless current_company.nil? %>
- <li><%= link_to "Company", current_company, :method => :get %></li>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement