Skip to content

Instantly share code, notes, and snippets.

@gorborukov
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save gorborukov/58f39016a9fa3bd4e26d to your computer and use it in GitHub Desktop.

Select an option

Save gorborukov/58f39016a9fa3bd4e26d to your computer and use it in GitHub Desktop.
/app/controllers/apartments_controller.rb & /app/views/layouts/print.html.erb & /app/config/routes.rb & /app/views/apartments/printable.html.erb
class ApartmentsController < ApplicationController
layout :choose_layout
def show
@building = Building.find params[:building_id]
@apartment = @building.apartments.find params[:id]
end
def printable
@building = Building.find params[:building_id]
@apartment = params[:apartment_id]
end
def choose_layout
case action_name
when 'printable'
'print'
else
'application'
end
end
end
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<%= yield %>
</body>
</html>
<%=# Printable content here %>
MorskoyKvartal::Application.routes.draw do
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
root :to => 'home#index'
match '/apartment_complex' => 'home#apartment_complex'
match '/tamansky_peninsula' => 'home#tamansky_peninsula'
match '/contacts' => 'home#contacts'
match '/callback' => 'home#callback'
match '/feedback' => 'home#feedback'
resources :construction_progress_albums, :only => [:show, :index]
resources :buildings, :only => [:show, :index] do
resources :apartments
end
resources :buildings do
resources :apartments do
match 'printable' => 'apartments#printable'
end
end
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment