sinatra

Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter

强颜欢笑 提交于 2019-12-03 08:18:40
For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself. I built a default facebook app. The Gemfile: source :gemcutter gem "foreman" gem "sinatra" gem "mogli" gem "json" gem "httparty" gem "thin" gem "data_mapper" gem "heroku" group :production do gem "pg" gem "dm-postgres-adapter" end group :development, :test do gem "sqlite3" gem "dm-sqlite-adapter" end Datamapper setup: # Setting up the database DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}

How to use sinatra session

霸气de小男生 提交于 2019-12-03 06:31:19
enable :sessions get '/foo' do session['m'] = 'Hello World!' redirect '/bar' end get '/bar' do session['m'] # => 'Hello World!' end It does not seem to work. Are you using shotgun? If so, do the following: configure(:development) { set :session_secret, "something" } This will no longer be necessary in Sinatra 1.3. Perhaps you have cookies disabled on your web browser? Sinatra's sessions use cookies by default. Here's my test app: require 'sinatra' enable :sessions get '/foo' do session['m'] = 'Hello World!' redirect '/bar' end get '/bar' do <<-ENDRESPONSE Ruby: #{RUBY_VERSION} Rack: #{Rack:

Accessing headers from Sinatra

放肆的年华 提交于 2019-12-03 06:22:51
I am trying to access the headers in a filter in sinatra. My request includes the header "HTTP_AUTH", however I can't access it. My filter is before do halt 403 unless request['HTTP_AUTH'] == 'test' end It works correctly from my rack test. browser.get '/mypath', "CONTENT_TYPE" => "application/json", "HTTP_AUTH" => 'test' But when I try from other sources I can't access it. If I puts request.env I can see the token is in the request, but I can't access it. "HTTP_CONNECTION"=>"close", "HTTP_AUTH"=>"test", "HTTP_ACCEPT"=>"application/json", What am I doing wrong? Try use before block with

sinatra helper in external file

谁都会走 提交于 2019-12-03 06:13:29
I have lot of helpers in my main Sinatra project_name.rb and I want to remove them to the external file, what is the best practice to do that ? from ./preject_name.rb helpers do ...#bunch of helpers end to for exapmple ./helpers/something.rb thank you Just as you said it yourself: Move the helpers block into another file and require it where you need. #helpers.rb helpers do ... end #project_name.rb require 'path/to/helpers.rb' The simple and recommended way: module ApplicationHelper # methods end class Main < Sinatra::Base helpers ApplicationHelper end Alas, if, like me, you are building a

Sinatra success stories [closed]

末鹿安然 提交于 2019-12-03 05:43:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . Have you used Sinatra successfully? What kind of a project was it? In what situations would you recommend using Sinatra instead of Rails or Merb? 回答1: I've dabbled with Sinatra, but haven't really written anything serious with it. As you said above, there's a list at http://www.sinatrarb.com/wild.html, although

Where does RACK log to?

為{幸葍}努か 提交于 2019-12-03 05:27:55
I am running a sinatra app through RACK. To which file does the activity get logged ? Also how can I set the log file path ? include It depends. Many developers define their app log file to app/servername.log or just to the current path where the Rack app is loaded. Yes you can change it's path. Usually you get a config.ru file with something like: log = File.new("sinatra.log", "a+") $stdout.reopen(log) $stderr.reopen(log) # optionally to sync logs while the server is running $stderr.sync = true $stdout.sync = true and/or configure do LOGGER = Logger.new("sinatra.log") enable :logging, :dump

What do you use Sinatra for? [closed]

烂漫一生 提交于 2019-12-03 05:27:15
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Im confused about Sinatra (the ruby framework). Is it a lightweight Rails replacement or you can have them running side by side? Can you do a web application (as in Rails)? For example a twitter clone? Sinatra is not Rails. It is a micro-framework used for

Best way to cache a response in Sinatra?

南笙酒味 提交于 2019-12-03 04:36:52
问题 I'm building a simple app on the side using an API I made with Sinatra that returns some JSON. It's quite a bit of JSON, my app's API relies on a few hundred requests to other APIs. I can probably cache the results for 5 days or so, no problem with the data at all. I'm just not 100% sure how to implement the caching. How would I go about doing that with Sinatra? 回答1: Personally, I prefer to use redis for this type of things over memcached. I have an app that I use redis in pretty extensively,

How to render a partial in sinatra view (haml in haml)?

被刻印的时光 ゝ 提交于 2019-12-03 04:22:46
问题 I have a simple sinatra app that uses haml and sass for the views. One of the views (located in the views folder) is a partial for my navigation menu. I am trying to render it from index.haml but I get the following error: wrong number of arguments (1 for 2) I am trying to render it with the following lines in index.haml .navigation = render :partial => "nav" 回答1: EDIT: !!! OUTDATED !!! Read Jason's answer below! What are you trying works in rails ! Sinatra has no partial method. An

Contact form in ruby, sinatra, and haml

左心房为你撑大大i 提交于 2019-12-03 02:54:18
问题 I'm new to all three, and I'm trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with it (due to my inexperience with sinatra). Any help at getting this working would be appreciated, I can't seem to figure out/find the documentation for this sort of thing. haml code from the contact page: %form{:name => "email", :id => "email", :action => "/contact", :method => "post", :enctype => "text/plain"} %fieldset