sinatra

Where should I set HTTP headers, such as Expires?

爷,独闯天下 提交于 2019-12-08 09:50:25
问题 I want to deploy an app using Sinatra on Phusion Passenger w/ nginx. If I want to set the Expires header on my static content - stylesheets, say - there are appear to be three places where I could accomplish this. In my Sinatra app, using the API With Rack middleware In the server config for my deployment Which of these methods is the best place for setting HTTP headers? 回答1: After talking though and answering this question and seeing the comment above, I think I have figured out the answer

will_paginate helper undefined in sinatra with mongoid

China☆狼群 提交于 2019-12-08 08:57:47
问题 I am using sinatra 1.4.3 and mongoid 3.1.4. I tried adding will_paginate gem from master branch for mongoid support so I added this to my gemfile: gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'master' In environment.rb I added: require 'will_paginate' require 'will_paginate/mongoid' And pagination method started working. I have still problem with will_paginate helper. In my views I get errors like: NoMethodError: undefined method `will_paginate' for #

Simple way to cache twitter gem tweet in Sinatra?

a 夏天 提交于 2019-12-08 08:35:22
I'm running into API Limit Requests which end up blowing my site up. Right now to avoid that I have the tweet request from the Twitter gem in a rescue block that returns a default string if something bad happens. I'm wondering what would be the best way to cache the latest tweet simply using: @twitter = Twitter.user_timeline("some_user", :include_rts => 1, :count => 1).first In case the API limit is hit? I use memcache (or now dalli ) for stuff like that. There are two options. You could hit the cache first and if the timestamp is within a certain threshold, just return the cached value

what is attr_accessor in datamapper - ruby

心已入冬 提交于 2019-12-08 08:27:07
问题 I am a newby in datamapper. I saw this code in this forum. class User include DataMapper::Resource property :id, Serial property :email, String, :required => true, :unique => true, :format => :email_address, property :name, String property :hashed_password, String property :salt, String property :created_at, DateTime attr_accessor :password, :password_confirmation property would mean that it defines the field in the database table..what does attr_accessor means..is it kind of field in the

Errors with shotgun gem and msvcrt-ruby18.dll when running my Sinatra app

不问归期 提交于 2019-12-08 07:12:58
问题 Greetings, Every time I make a change to a Sinatra app I'm working on and try to refresh the browser (located at http://localhost:4567/) the browser will refresh and, the console window seems to restart the WEB brick server. The problem is that the content in the browser window does not change. A friend of mine told me it was a shotgun issue and referred me to rtomayko's shotgun gem: http://github.com/rtomayko/shotgun On this page I read that the shotgun gem would basically solve my problem,

How to use Kaminari pagination gem with Sinatra and Mongoid?

邮差的信 提交于 2019-12-08 06:40:31
问题 Presumably, not a whole lot of configuration is required - docs. The gem doesn't seem to work. Relevant code: Gemfile: source 'https://rubygems.org' ruby '2.2.4' gem 'sinatra' gem 'thin' gem 'slim' gem 'json' gem 'mongoid' gem 'kaminari' web.rb: require 'sinatra' require 'json' require 'mongoid' require 'kaminari' # Mongoid class class Affiliate include Mongoid::Document field :name, type: String end # MongoDB connection info and whatnot Mongoid.load!('mongoid.yml', :development) get '

Simple way to cache twitter gem tweet in Sinatra?

白昼怎懂夜的黑 提交于 2019-12-08 06:40:05
问题 I'm running into API Limit Requests which end up blowing my site up. Right now to avoid that I have the tweet request from the Twitter gem in a rescue block that returns a default string if something bad happens. I'm wondering what would be the best way to cache the latest tweet simply using: @twitter = Twitter.user_timeline("some_user", :include_rts => 1, :count => 1).first In case the API limit is hit? 回答1: I use memcache (or now dalli) for stuff like that. There are two options. You could

how can I use like query in ruby with sinatra?

依然范特西╮ 提交于 2019-12-08 04:11:32
问题 Here's the query I tried: @blogs = DB[:blogs].where(:title => params[:s_txt]).reverse_order(:id) In this query, I'd like to find blogs in my database. I also need to create a query that gives users more results. How can I do this? 回答1: I also had this problem and only found this solution @blogs = DB[:blogs].where("title LIKE '%#{params[:s_txt]}%'").reverse_order(:id) Curious if there are better ways.. Searching in two fields is repeating the LIKE and seperating by AND or OR @blogs = DB[:blogs

How do I get an array of check boxes in haml?

会有一股神秘感。 提交于 2019-12-08 04:02:23
问题 I have an array of strings, called @theModels, in a routine implemented as part of a Sinatra server. These models are options for the user to select, and are obtained by the back end (the idea being, as new models are added, then the front end code should not change). I'm using haml to render html. How can I enumerate each element in the list of @theModels such that each element is a checkbox? And how can I obtain which checkboxes the user has selected? I see that just putting = @theModels

Rack::ResponseHeaders in rackup for Sinatra

血红的双手。 提交于 2019-12-08 03:52:34
问题 I think this is a very easy one, but I can't seem to get it right. Basically, I'm trying to use Rack middleware to set a default Cache-Control header into all responses served by my Sinatra app. It looks like Rack::ResponseHeaders should be able to do exactly what I need, but I get an error when attempting to use the syntax demonstrated here in my rackup file: use Rack::ResponseHeaders do |headers| headers['X-Foo'] = 'bar' headers.delete('X-Baz') end I was able to get Rack::Cache to work