Skip to content

Instantly share code, notes, and snippets.

@almonk
Created November 27, 2013 14:22
Show Gist options
  • Save almonk/7676447 to your computer and use it in GitHub Desktop.
Save almonk/7676447 to your computer and use it in GitHub Desktop.
class MenusController < InheritedResources::Base
http_basic_authenticate_with name: "duh", password: "secret"
def new
@menu = Menu.new
@menuitems = Menuitem.all
@menuTags = []
@menuitems.each do |item|
@menuTags << item.description
end
end
def index
@menus = Menu.find(:all, :order => "created_at DESC", :limit => '14')
index!
end
def print
@menu = Menu.find(params['id'])
menuHtml = render_to_string 'menus/print', :layout => 'print'
@hypdf = HyPDF.htmltopdf(
menuHtml,
orientation: 'Portrait',
copies: 1,
test: true
)
# send PDF to user
send_data(
@hypdf[:pdf],
filename: "menu.pdf",
type: 'application/pdf'
)
end
def print_test
@menu = Menu.find(params['id'])
render 'menus/print', :layout => 'print'
end
def create
@menu = Menu.create(menu_params)
redirect_to menu_path(@menu)
end
def update
@menu = Menu.find(params[:id])
@menu.update_attributes!(menu_params)
redirect_to menu_path(@menu)
end
private
def menu_params
params.require(:menu).permit(:id, :name, :date, menuitems_attributes: [:id, :description, :price, :_destroy])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment