sinatra

Sinatra not persisting session with redirect on Chrome

核能气质少年 提交于 2019-12-03 11:55:21
Sinatra is not persisting my session with a redirect on Chrome. It is creating an entirely new session and i'm losing all my previous session data. As an example (similar to the Sinatra docs ), i'm doing something like this: enable :sessions get '/foo' do session[:user_id] = 123 session[:session_id] # "ABC", for example redirect to('/bar') end get '/bar' do # this is "DEF" when responding to Chrome (wrong), # but "ABC" when responding to Firefox or Safari (right) session[:session_id] # this is nil when responding to Chrome (wrong), # but 123 when responding to Firefox or Safari (right) session

Deploy Gollum wiki to Heroku

倾然丶 夕夏残阳落幕 提交于 2019-12-03 11:24:19
Gollum is "A simple, Git-powered wiki with a sweet API and local frontend." It's hosted on GitHub: http://github.com/github/gollum It seems to be a simple Sinatra app, and as such, it seems like it should be easy to deploy to Heroku. I can't seem to get it to work. Mostly because I know next to nothing about Rake and config.ru files. Is it even possible to deploy a Gollum wiki to Heroku? If so, what would my config.ru file need to look like? Update/Edit lib/gollum/frontend/app: module Precious class App < Sinatra::Base This gets called from bin/gollum require 'gollum/frontend/app' Precious:

Devise with Sinatra

你。 提交于 2019-12-03 11:11:13
问题 Does anyone had installed Devise gem with Sinatra? Devise is based on Warden and so it should work on Sinatra, I couldn't find any related info about how to implement it. 回答1: Devise is really just a Rails-centric wrapper with nice helpers for warden, which is the underlying Rack authentication framework. So if you're using Sinatra in conjunction with Rails, you can use Devise in your Rails app, and use warden directly in your Sinatra app, and they will see the same user session data. So no,

What python equivalent of Sinatra would you recommend? [closed]

时光怂恿深爱的人放手 提交于 2019-12-03 10:48:14
问题 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. Closed 7 years ago . I like the sinatra framework, but might have to work in python. A quick web search has uncovered a few python equivalents including

Deleting the current session with Rack::Session::Cookie

与世无争的帅哥 提交于 2019-12-03 10:47:24
问题 I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-) enable :sessions get '/logout' do # What goes here to kill the session? end 回答1: Just use session.clear to destroy the session. 回答2: It depends how you create your session. Simply you have to nulify session entry. Here is simple example, how to create and destroy sessions. get '/login' do session[:username] = params[:username] "logged

How can I send binary data from Sinatra?

非 Y 不嫁゛ 提交于 2019-12-03 10:16:48
I want to send binary data from a Sinatra application so that the user can download it as a file. I tried using send_data but it gives me an undefined method 'send_data' How could I achieve this? I could write the data to a file and then use send_file but I would rather avoid doing this. you can just return binary data: get '/binary' do content_type 'application/octet-stream' "\x01\x02\x03" end I did it like this: get '/download/:id' do project = JSON.parse(Redis.new.hget('active_projects', params[:id])) response.headers['content_type'] = "application/octet-stream" attachment(project.name+'

Sinatra - how do I get the server's domain name

爱⌒轻易说出口 提交于 2019-12-03 09:31:17
I'm trying to get the domain name in my Sinatra app but as a newbie I really am struggling to figure out how to do this, and I know it must be possible! Rack::Request#host_with_port looks promising, but I don't know how to get this from my app - how do I get stuff from Rack in my Ruby code? Or is there another way - I'm thinking I don't really want to do this every time a request happens (although it's not too bad), but I thought it'd be better if I could just do it once when the application loads up. Any hints? simply use request.host inside your code. get "/" do puts request.host #=>

In a Sinatra App on Heroku, Session Is Not Shared Across Dynos

…衆ロ難τιáo~ 提交于 2019-12-03 09:14:51
问题 Which makes sense. But what are some preferred work arounds for this issue? 回答1: In my comment, I suggested using rack cookie based sessions, but looking into it, the Sinatra sessions are Rack cookie sessions anyway. Looking further, I found this in the Sinatra docs: To improve security, the session data in the cookie is signed with a session secret. A random secret is generate for you by Sinatra. However, since this secret will change with every start of your application, you might want to

Sinatra, MySQL and ActiveRecord

Deadly 提交于 2019-12-03 08:52:16
问题 how do I set up a simple sinatra app to use MySQL and ActiveRecord? I found some solutions, but none of them worked (maybe they are outdated): http://ericfarkas.com/posts/sinatra-activerecord-and-mysql/ http://labs.thredup.com/setting-up-sinatra-with-mysql-and-activerecor So what is the best practise method, to use Sinatra along with MySQL and ActiveRecord? The https://github.com/janko-m/sinatra-activerecord gem is only for sqlite3, as far as I can see. I'm not sure if I need models or just

Robust way to deploy a Rack application (Sinatra)

我与影子孤独终老i 提交于 2019-12-03 08:40:48
I'm looking for a robust way to deploy a Rack application (in this case a Sinatra app). Requests will take a little time (0.25-0.5 sec waiting on proxied HTTP requests) and there may be a decent amount of traffic. Should I go with a traditional mongrel cluster setup? Use HAProxy as a load balancer? nginx? rackup? What solutions have you used and what are the advantages? Nginx / Unicorn FTW! Nginx in front to serve static files and unicorn to handle Sinatra app. Benefits: Performance, good load balancing with unix socks and deploy/upgrade without any downtimes (you can upgrade Ruby/Nginx