sinatra

Sinatra custom SASS directory

£可爱£侵袭症+ 提交于 2019-12-11 10:54:34
问题 I have problem getting my sass work with my haml template. Recently i have following code in my main sinatra.rb application: require 'sinatra' require 'dm-core' require 'dm-migrations' require 'haml' require 'sass' require 'shotgun' set :views, :sass => 'views/css', :haml => 'template', :default => 'views' helpers do def find_template(views, name, engine, &block) _, folder = views.detect { |k,v| engine == Tilt[k] } folder ||= views[:default] super(folder, name, engine, &block) end end get '

Sinatra matches params[:id] as string type, additional conversion needed to match the database id?

隐身守侯 提交于 2019-12-11 10:15:57
问题 I am using sinatra and DataMapper to access an sqlite3 database. I always get an nil when calling get(params[:id]) . But when I call get(params[:id].to_i) I can get the right record. Is there anything wrong such that I have to do the conversion explicitly? The sinatra app is simple: class Record include DataMapper::Resource property :id, Serial .... end get '/list/:id' do r = Record.get(params[:id]) ... end 回答1: Obviously this is a problem with Datamapper (if you believe it should be casting

allow others to see your Sinatra local server through amazon instance

安稳与你 提交于 2019-12-11 09:38:27
问题 It's really difficult to explain. But basically, I have an amazon instance, and I want to ssh into it and run a local server on it with sinatra. so I would ssh into the amazon instance, git clone my repo, and run ruby config.ru. Then I want someone else to be able to see that exact local server that is being ran. One of the things I've done is added a security group, port 4567 HTTP so that I can access it via public dns. It works on a rack app but it doesn't work on the sinatra, I've even

Problems getting my sinatra based app to work on Heroku

一曲冷凌霜 提交于 2019-12-11 09:36:35
问题 I made a simple Sinatra app to run a homepage. It's already working on my computer. Now I wanted to host it at heroku, but I can't manage it to make it run. I am not really familiar with concepts like "Gemfile" or "Procfile". My ruby app requires Sinatra, haml and sinatra/r18n. My gemfile looks like this: source :rubygems gem 'sinatra' gem 'thin' gem 'sinatra-r18n' gem 'haml' My Procfile looks like this: web: bundle exec ruby app.rb -p $PORT My app.rb starts like this: # app.rb require

Sending mail with Pony and Sinatra

筅森魡賤 提交于 2019-12-11 09:33:42
问题 I am trying to send an email from a contact form (built in HTML) with the Pony Gem within sinatra, I have followed the docs but something must be missing. This is the Pony config get '/contact' do erb :contact, :layout => :layout end post '/contact' do require 'pony' Pony.mail({ :from => params[:name], :to => 'myemailaddress', :subject => params[:name] + "has contacted you via the Website", :body => params[:comment], :via => :smtp, :via_options => { :address => 'smtp.gmail.com', :port => '587

No perfomance gains from using em-http-request

被刻印的时光 ゝ 提交于 2019-12-11 09:32:27
问题 I'm trying to understand how to use various non-blocking IO libraries in Ruby and made a simple app for testing using Sinatra, # proxy.rb require 'bundler/setup' require 'sinatra/base' require 'sinatra/synchrony' require 'faraday' class ProxyApp < Sinatra::Base register Sinatra::Synchrony get "/proxy" do conn = Faraday.new("http://mirror.yandex.ru") do |faraday| faraday.use Faraday::Adapter::EMSynchrony end conn.get "/ubuntu-releases/precise/ubuntu-12.04.1-alternate-i386.iso" "Hello, world"

Calling Sinatra from Sinatra produces results different from external request

∥☆過路亽.° 提交于 2019-12-11 08:27:33
问题 Following my question here. So I am trying to do a smart redirect using this: get "/category/:id/merge" do #... setting @catalog_id and category call env.merge("PATH_INFO" => "/catalog/#{@catalog_id}/category/#{category.id}", "REQUEST_METHOD"=>"PATCH","QUERY_STRING"=>"merge=1") status 200 end But when I look in logs, I see something that is not only frustrating but also completely absurd: # this one is from internal call I, [2013-03-21T15:55:54.382153 #29569] INFO -- : Processing GET /catalog

Sinatra doesn't show POST data

懵懂的女人 提交于 2019-12-11 08:22:54
问题 I am making AJAX request from the client to Sinatra but somehow the data doesn't show up.Chrome request headers tab suggests that on the client side is everything OK: Request Payload { test: Data } However, on Sinatra's side post '/api/check/:name' do sleep 3 puts params.inspect end And the console: 127.0.0.1 - - [03/Feb/2014 10:45:53] "POST /api/check/name HTTP/1.1" 200 17 3.0019 {"splat"=>[], "captures"=>["name"], "name"=>"name"} Post data is nowhere to be found, what's wrong ? 回答1: It's a

NameError in using custom layout option in sinatra app

烈酒焚心 提交于 2019-12-11 08:19:52
问题 To use custom layout file in my app I'm using this following code, set :views, File.dirname(__FILE__) + "/../views" set :public_folder, File.dirname(__FILE__) + "/../public" get '/' do if !Db.empty? then haml :home, {:layout => :nosetup-layout} elsif request.ip == "127.0.0.1" then haml :setup, {:layout => :nosetup-layout} else haml :nosetup, {:layout => :nosetup-layout} end end there seems to be a problem with the layout option I get the following error undefined local variable or method

How to display websites in iframe

回眸只為那壹抹淺笑 提交于 2019-12-11 08:18:18
问题 I am using ruby and sinatra. I need to create a website that allows the user to upload a zipfile of other websites and display all of them in multiple iframes on the page but I'm not sure how to even start this. so far I have made the website that can upload a zipfile and have placed it in an uploads folder and i can display that on website by doing <iframe src="../uploads/test.html" width="100%" height="600"> <p>Your browser does not support iframes.</p> </iframe> post '/upload' do File.open