sinatra

Undefined method auto_upgrade! when pushing Sinatra/DataMapper app to Heroku

不羁岁月 提交于 2019-12-01 18:16:15
Does anybody know the magic incantation required to get a Sinatra application that uses DataMapper up and running on Heroku's Bamboo stack? The Bamboo stack doesn't include any pre-installed system gems and no matter what combination of gems I try I keep getting this error: undefined method `auto_upgrade!' for DataMapper:Module (NoMethodError) This is what I have in my .gems file: sinatra pg datamapper do_postgres dm-postgres-adapter And these are the dependencies that are installed when I push the app to Heroku: -----> Heroku receiving push -----> Sinatra app detected -----> Installing gem

Undefined method auto_upgrade! when pushing Sinatra/DataMapper app to Heroku

随声附和 提交于 2019-12-01 17:30:48
问题 Does anybody know the magic incantation required to get a Sinatra application that uses DataMapper up and running on Heroku's Bamboo stack? The Bamboo stack doesn't include any pre-installed system gems and no matter what combination of gems I try I keep getting this error: undefined method `auto_upgrade!' for DataMapper:Module (NoMethodError) This is what I have in my .gems file: sinatra pg datamapper do_postgres dm-postgres-adapter And these are the dependencies that are installed when I

Execute code once Sinatra server is running

做~自己de王妃 提交于 2019-12-01 17:25:14
I have a Sinatra Application enclosed in Sinatra::Base and I'd like to run some code once the server has started, how should I go about doing this? Here's an example: require 'sinatra' require 'launchy' class MyServer < Sinatra::Base get '/' do "My server" end # This is the bit I'm not sure how to do after_server_running do # Launches a browser with this webapp in it upon server start Launchy.open("http://#{settings.host}:#{settings.port}/") end end Any ideas? Using the configure block is not the correct way to do this. Whenever you load the file the commands will be run. Try extending run!

How does Sinatra define and invoke the get method?

最后都变了- 提交于 2019-12-01 16:46:55
I'm pretty curious about how this thing works. after require 'sinatra' then I can invoke get() in the top level scope. after digging into the source code, I found this get() structure module Sinatra class << self def get ... end end end know the class << self is open up the self object's singleton class definition and add get() inside, so it starts to make sense. But the only thing left I can't figure out is it's within module Sinstra, how could get() be invoked without using Sinatra:: resolution operation or something? It is spread out in a few places, but if you look in lib/sinatra/main.rb ,

How do I html_escape text data in a sinatra app?

廉价感情. 提交于 2019-12-01 16:36:22
I have a small Sinatra app which generates html fragments for me from an ERB template. How do I html_escape the output? The <%=h somestring %> helper does not exist in Sinatra. Rack::Utils includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html require 'CGI' get '/html' do erb :view end def h(html) CGI.escapeHTML html end __END__ @@view <% File.open('my.html') do |f| %> <%=h f.read() %> <% end %> 来源: https://stackoverflow.com/questions/2123586/how-do-i-html-escape-text-data-in-a-sinatra-app

How can I speed up Ruby/Rake task

十年热恋 提交于 2019-12-01 16:05:10
问题 rake --tasks takes about 18s to run. This is just the time it takes to load all the tasks, as a result any task I define will take at least this amount of time to run : $time rake --tasks rake db:clean # Cleaning up database rake passenger:restart # Restart Application rake spec # Run specs real 0m18.816s user 0m7.306s sys 0m5.665s My Rakefile : $: << "." require "rubygems" require "rspec/core/rake_task" desc "Run those specs" task :spec do RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts

will_paginate can it order by day

落花浮王杯 提交于 2019-12-01 12:47:07
问题 SCENARIO: I have a Pictures table that contains hundreds of photos. I'm currently using 'will_paginate' to paginate 100 photos per page. I would like to continue using 'will_paginate' BUT I want the pagination to be driven by the day. I have tried the following by using sort_by but I don't think it's working. @pics = Picture.paginate(:page => params[:page]).sort_by(&:created_at) END GOAL: Home page shows me today's pictures only. Now if I click on page 2 it shows me yesterdays pictures only.

Save all user entries from html text built off a loop using ruby and sinatra

本小妞迷上赌 提交于 2019-12-01 10:43:18
I am creating a web page that displays a table. It also has four columns at the end of each record that are text fields where the user can enter data. When the user hits the submit button at the bottom I want to save all the data in all the text fields and add it to my table. How can I save the data for all the text fields? Here is my code. <h1>Testing Table</h1> <form action="/table/" method="POST"> <table> <thead> <tr> <% event_column.each do |header| %> <th> <%= header %> </th> <% end %> </tr> </thead> <tbody> <% events.each do |event| %> <tr> <% event = event.first(14) %> <% event.each do

How to access *incoming* headers in Sinatra?

冷暖自知 提交于 2019-12-01 08:54:19
I'm sending a request to a Sinatra application by this: curl -X POST --header "MyHeader: 123444" http://localhost:9292/test -d "" How can I access it in the route? These don't work: headers["MyHeader"] request["MyHeader"] request.env["MyHeader"] They're all nil. Have you tried adding HTTP to the header name? So it would be request.env["HTTP_ MyHeader"] This is part of the rack spec. 来源: https://stackoverflow.com/questions/35787395/how-to-access-incoming-headers-in-sinatra

Ruby Rack: startup and teardown operations (Tokyo Cabinet connection)

梦想与她 提交于 2019-12-01 08:46:45
I have built a pretty simple REST service in Sinatra, on Rack. It's backed by 3 Tokyo Cabinet/Table datastores, which have connections that need to be opened and closed. I have two model classes written in straight Ruby that currently simply connect, get or put what they need, and then disconnect. Obviously, this isn't going to work long-term. I also have some Rack middleware like Warden that rely on these model classes. What's the best way to manage opening and closing the connections? Rack doesn't provide startup/shutdown hooks as I'm aware. I thought about inserting a piece of middleware