FAQ Database Discussion Community


Parsing request JSON in Sinatra app

ruby,json,sinatra
I am having some difficulty with parsing the JSON from a request to my Sinatra application: response = JSON.pretty_generate(request.env) reply = response["rack.request.form_hash"] results in reply just returning: rack.request.form_hash as a string rather than just the relevant part of the response: {... "rack.request.form_hash": { "token": "token", "team_id": "team", "team_domain": "teamname", "service_id":...

Sorting tweets by re-tweets/favourites

ruby,twitter,sinatra,erb
I'm trying to implement a method whereby a user can manipulate three radio buttons, each with assigned methods, to sort the tweets either by retweets, by favourites or default(by date). Currently, the page lists the tweets by date as default but every time I pressed either of the two buttons,...

undefined method `namespace'

ruby-on-rails,ruby,gem,sinatra
I'm trying implement a namespace(with sinatra-contrib gem) routing for Sinatra app and have an error after I'm trying to start the server: undefined method `namespace' for GuessApp:Class app.rb require 'sinatra' require 'sinatra/namespace' require 'haml' require_relative 'routes/init' require_relative 'models/init' require_relative 'helpers/init' class GuessApp < Sinatra::Base register Sinatra::Namespace end routes/init.rb require_relative "books"...

How to connect Flux to Sinatra API

javascript,architecture,sinatra,reactjs,reactjs-flux
I'm using React for a web application, and I've started learning about Flux. I like the concept of a unidirectional data flow, but I'm having some problems understanding how that connects to an API. I have a back end written in Sinatra. What I'm confused about is how does the...

why am I getting a load error for mandrill-api gem on aws?

ruby,amazon-web-services,sinatra,mandrill
I am using Sinatra and ruby on AWS, I have tried with both 2.1 and 1.9.3 using the AWS cli to create my elasticbeanstalk application. I have installed the mandrill-api gem on my local machine and ruin bundle install (although that may not be necessary) and included it in the...

Sinatra Rack Test “0 Tests” run

ruby,unit-testing,sinatra,rack-test
I'm trying to get some unit tests written for a small Sinatra app. When I run ruby test.rb, the terminal reports that it is "running tests" but it is not actually picking up my unit tests. The app itself runs fine whether by locally typing ruby app.js or through phusion...

How to override default Internal Server Error in Ruby/Sinatra to display erb file

ruby,error-handling,sinatra,internal-server-error
I want to override the normal sinatra internal server error so it instead displays an erb file. So far I have this: set :show_exceptions, :after_handler error 400..510 do erb :error end But it doesn't work... any ideas?...

Disable Sinatra standard output

ruby,sinatra
For security reasons I don't wish to have Sinatra print every URL its requested in standard output, I've tried using set :logging, false as suggested in this answer using: class SweetAppName< Sinatra::Base set :show_exceptions, false set :environment, :production set :logging, false However when I run the app using rackup and...

How to get data from other tables using Sequel

ruby,sinatra,sequel
I use Sequel and I have the following 2 models in my Sinatra app # foo.rb require 'sequel' module Notes module Models class Foo < Sequel::Model plugin :json_serializer, naked: true plugin :validation_helpers one_to_many :bars def validate super validates_presence [:foo_name], message: "can't be empty" end end end end # bar.rb require...

How can I make a HTTP request from one docker container to another linked container?

node.js,sinatra,docker,boot2docker,faraday
I have a docker container with an sinatra app inside, and another container with an node.js app. They are both linked through Fig. In my sinatra app I am making a HTTP Post request to the node.js app. For that I am using the Faraday gem. My questions is now...

How do I write Slim helpers in Sinatra?

ruby,sinatra,slim-lang
I'm using Sinatra and Slim. I'm trying to work out how to write a helper for Slim so I can DRY-up my templates. (In this case the helper is small and I could get away with in-line Ruby, but in future I would do more complex things). I have the...

Ruby Sinatra configured to work on production and development

ruby,sinatra
I've created the application on Sinatra, which represents a simple API. I want to make deployment on production and development. I want to choose during deployment, whether it should be dev or production, and the logic of some methods should change, depending on deployment type. Is there any idea, how...

Read parameters via POST with Ruby + Sinatra + MongoDB

ruby,mongodb,post,sinatra
I'm creating a simple API with Sinatra + Ruby + MongoDB, working via GET not have problems, but via POST yes... I try to receive params but this come in empty, I don't know if I'm doing thing not good. I am not working with view html, just request and...

Can't access Ruby server on VM from host machine

ruby,sinatra,virtual-machine
I have a VM set up running Ubuntu server 14.04. In my VM I have created the following Ruby/Sinatra app: require 'sinatra' set :environment, :production set :bind, '0.0.0.0' get '/' do "Hello World!" end When I execute this using ruby hello.rb I get the following output: [2015-03-09 16:58:34] INFO WEBrick...

Ruby : uploaded files suddenly become not found within hours in heroku

java,ruby,heroku,sinatra
I have the following post code for Ruby Sinatra to upload image files : post "/upload" do File.open("public/uploads/" + params["image"][:filename], "wb") do |f| f.write(params["image"][:tempfile].read) end end And the following Java codes to upload the image file to example.com/upload : private static String boundary; private static final String LINE_FEED = "\r\n";...

how can I acess elements of a JSON retunr from a Stripe api call?

ruby,sinatra,stripe-payments
I am using ruby and sinatra. After a Stripe API call, I want to access an element, from a JSON return, and put it into my database. The ruby code is: require 'sinatra' require 'stripe' require 'pg' require 'sequel' get '/save_customer' do customer = Stripe::Customer.retrieve("cus_6EfJSbJ8gCTxxx") puts customer last4 = customer["sources"]["data"]["last4"]...

Using pry with Sinatra [closed]

ruby,sinatra,pry
New to Ruby and Sinatra. I'm trying to use pry within a Sinatra controller (want to be able to take a look at what params is returning to me). I added a 'binding.pry' inside of the Post request, but it's not working. I know I need to require 'pry' but...

Creating a Ruby API

ruby,api,sinatra
I have been tasked with creating a Ruby API that retrieves youtube URL's. However, I am not sure of the proper way to create an 'API'... I did the following code below as a Sinatra server that serves up JSON, but what exactly would be the definition of an API...

Instagram access_token returning BadRequest error

ruby,sinatra,instagram,instagram-api
I'm working with the Instagram gem and getting an unexpected bad request error when calling Instagram.user_recent_media. get '/api/photos' do client = Instagram.client(:access_token => session[:access_token]) puts 'access token: ' << session[:access_token].inspect id = params[:id] photos = Instagram.user_recent_media(id, {:max_id => params[:max_id]}) end It's throwing this error: Instagram::BadRequest - GET https://api.instagram.com/v1/users/35099128/media/recent.json?client_id=12345&max_id=: 400: you...

How does Sinatra allow its syntax?

ruby,sinatra
One of Sinatra's examples is this: require 'sinatra/base' class MyApp < Sinatra::Base set :sessions, true set :foo, 'bar' get '/' do 'Hello world!' end end How does Sinatra allow the " get '/' do" syntax? It doesn't seem to be a method, and I'm not aware of any other syntax...

ActiveRecord get all + associated details

ruby,activerecord,sinatra
I am trying to retrieve a list of all tasks, where each task has a developer and reviewer. I am able to retrieve the list but it contains developer_id and reviewer_id. How do I retrieve a list containing developer name and retriever name? class Person < ActiveRecord::Base end class Unread_Object...

sinatra start as daemon programmatically

ruby,sinatra,daemon
Right now, after having loaded everything my executable runs my app like this: Rack::Handler::pick(['puma']).run VCK::App and it works, but it blocks the terminal (which is ok for development) How do I get this to start as a daemon programmatically from within my executable? EDIT: Code I use to start sinatra...

Sinatra Catching Exceptions for Custom Error Pages

ruby,exception,exception-handling,sinatra
I am trying to handle errors in a Modular Sinatra App. We raise various error through out the app and I wrote some thing alike to catch errors thinking it will happen hierarchically. My the file I use to error handle looks like the following. #!/usr/bin/env ruby # @class class...

Environment variables not showing up on Openshift ruby 2.0

ruby,sinatra,openshift,openshift-client-tools
I've been playing around with Open Shift and tried to pass an environment variable. First, I set it with rhc env set TEST=foo -a myApp. Then I ensured it was there with rhc env list -a myAPP, and it was. Nest, in my app, I put Test variable = <%=...

Using Sinatra and DataMapper, are classes one and the same?

ruby,class,sinatra,datamapper
When declaring classes in a sinatra app for data mapper, I understand it would look something like this: class Thing include DataMapper::Resource property :id, Serial property :name, String property :num, Integer end And if this wasn't a web app, but just desktop ruby program, you might do something like this:...

How do I associate an Activerecord Object with Em-Websocket connection?

ruby,activerecord,sinatra,em-websocket
I am new to ruby. I am trying to implement a chat client using em-websocket. I have the following code: EventMachine::WebSocket.start(host: '0.0.0.0', port: 8080) do |websock| websock.onopen do puts 'New Connection Opened' cookies = CGI::Cookie::parse( websock.request["cookie"]) person = Person.where(['token = ?', cookies["token"]]).first unless person websock.close(code = nil, body = {Error:...

Prevent Display Of Html Tags From User Input Sinatra?

ruby,heroku,sinatra
I have an app where users can input whatever they want, and it will show up on a separate page. I would like to have it display exactly what the user inputs and not process the tags as html. For example if a user inputs let me use a <hr>...

How can I test multistep forms with Capybara & Minitest?

ruby,testing,sinatra,capybara,minitest
I have a single page Sinatra app that has a multistep form/wizard interface. If I want to test the form with Capybara, will need to repeat all the steps for each test? I'm hoping to avoid something like this: it "visits the home page" do vist "/" page.should have_content('foo') end...

Sinatra randomly starts demo server

ruby,sinatra
I am writing a small proxy-checking utility, here is my code so far: require "thread" require "socket" require "http" require "sinatra" host = "0.0.0.0" port = 6660 Thread.new do class App < Sinatra::Base set :server, :thin get '/' do env.select {|k,v| k.start_with? 'HTTP_'}.collect {|pair| "#{pair[0].sub(/^HTTP_/, '')}: #{pair[1]}"}.join "\n" end end...

Symlinking unicorn_init.sh into /etc/init.d doesn't show with chkconfig --list

sinatra,server,unicorn,centos6
I'm symlinking my config/unicorn_init.sh to /etc/init.d/unicorn_project with: sudo ln -nfs config/unicorn_init.sh /etc/init.d/unicorn_<project> Afterwards, when I run chkconfig --list my unicorn_ script doesn't show. I'm adding my unicorn script to load my application on server load. Obviously, this is not allowing me to add my script with: chkconfig unicorn_<project> on Any...

Displaying information from a SQL DB into an ERB webpage

ruby,database,sqlite,sinatra,sequel
I am creating a program with a search bar that searches my SQL DB within my project. Index.erb: I have the code for the search bar in my index.erb file. <form method="get" action="/submit"> <input placeholder="Search" type="text" name="userInput"/> <input type="submit" value="Search" /> </form> App.rb: In myapp.rb file I use params[:userInput] to...

Execute action in web server without client request

ruby,webserver,sinatra
I am working on Sinatra single purpose application which is making api calls to some service. I would like if server could perform that action at predetermined time and have results stored for client when requested. Right now I refresh only on user request as: class App < Sinatra::Base get...

Force Sinatra to quit when hanging

sinatra
After a control - c to quit the server I get the message == Sinatra has ended his set (crowd applauds) [2015-06-21 16:38:58] INFO going to shutdown ... and then it just hangs there and doesn't exit. Is there a way to force it to quit? I have to close...

Set database.yml using environment variables in Sinatra

mysql,ruby,orm,sinatra,sinatra-activerecord
I have a very weird requirement in a project I am working on. I have file stored in some location /etc/config/config.json which contains database information like Host, Port, Username or Passwordor roughly looks as below: { "mysql-db": { "host": "172.17.0.27", "port": 3306, "password": "root", "username": "root" } } I am...

When and where does Sinatra's request object exist?

ruby,sinatra
I'm stumped I've tried everything I can think of to work around this and I got nothing. When does Sinatra's request object start existing and where does it actually exist and how can I get to it from anywhere? i.e. another class that inherits from a class that inherits from...

Bundle install not working on Windows

ruby,heroku,sinatra,bundler,heroku-toolbelt
I am trying to deploy my Sinatra app on Heroku server and for that i need to follow few steps. One of them is "Bundle install" but I am facing below issue while executing "Bundle install" - [I am using windows machine] I saw many posts on this site for...

How execute “rackup” from a remote path?

ruby,osx,sinatra
Running a rack service written in ruby, I need to execute "rackup" from an external path, without browsing into the code's directory previously. classically: cd /Volumes/Code/my_service; rackup i'd like to: rackup cd /Volumes/Code/my_service which obv does not work because rackup doesnt not take this parameter....

Sinatra cannot find file that is clearly there

ruby,heroku,sinatra
I do not know what to do. It is giving me this error on the line which contains erb :RUSure I don't understand why that is different from any other lines where I use erb :whateverFileName It is not that it is in a different directory, because it is in...

Sinatra, wrong server is being used - Thin instead of Puma

ruby,sinatra,thin,puma
Right, I'm building a sinatra app that needs to be threadable (as I'm using sucker-punch for jobs) and I want to use the puma server to do it (I've never used it before)) But for some reason when I start my app it runs the thin. Now, I uninstalled thin...

ActiveRecord on Sinatra basic associations and IDs

ruby,activerecord,sinatra
I'm newbie Grails user trying out ActiveRecord on Sinatra. Basically I want to make a CRUD app that allows a logged-in user to list down his products. I made a Users table and a Products table, with Users and Products referencing each other. When a user enters a product, ActiveRecord...

Calling a Ruby Method via a html button in sinatra

ruby,sinatra
I'm trying to build an e-commerce site using Sinatra, as practice. I'm getting stumped on how to implement the 'Add to Cart' Button. My thought process about it is: User clicks 'add to cart' The button 'add to cart' invokes a ruby method, for example clicking on the following button...

How to link a css file with the Slim templating engine?

css,ruby,sinatra,slim-lang
i am working on a little Sinatra/Slim project, and i want to include a css file. All works fine except that. Here is my project "tree": ├── essai.rb └── views ├── form.slim └── style.css And this is the head of form.slim: html head title Vote link href="style.css" rel='stylesheet' type='text/css' I've...

Ruby and Sinatra problems with session

ruby,session,sinatra
I used sinatra session in my ruby project. After login I write in session[:name] the name of user. If user call some API method I verify session[:name] and if this value is not empty he get response from the server. After logout I clear this value. My code: use Rack::Session::Cookie,...

How to write portable image paths in CSS files for a mounted sinatra app?

sinatra,rack
Background You are writing a sinatra (or rack) application, and want to be able to use it, with no code changes, both as a standalone app, or as a mounted app. That is, you might run this application on its own, or you might mount it as a sub-application inside...

I'm getting an error when I try to register a module with sinatra

ruby,sinatra
I'm getting this error: /.rvm/gems/ruby-2.1.3/gems/sinatra-1.4.5/lib/sinatra/base.rb:1388:in `register': undefined method `+' for nil:NilClass (NoMethodError) when I try to register an extension using either context.send method, component or context.instance_eval "#{method} #{component}",__FILE__,__LINE__ context = App < Sinatra::Base method = :register component = Sinatra::ModuleName Thing is doing the same thing with helpers works perfectly fine,...

something's wrong with the css path in my haml file

css,ruby,path,sinatra,haml
The directory structure is as follows: approot ` public ` css - main.css ` views - home.haml - index.haml - main.rb and I've tried to call my css in the haml file with: %link{:rel => "stylesheet", :href => url('css/main.css')}, %link(rel="stylesheet" href="css/main.css") and %link{:rel => "stylesheet", :href => "css/main.css"} Nothing works...

Sending email from simple Sinatra app using Pony

ruby,email,sinatra,pony
I am building my first portfolio page with Sinatra. I have a 'textbook' contact page with a straight-forward form containing 'name', 'email' and 'content' fields. When someone submits the form, I want to recieve an email notification. Pony claims that it can send email via simple 'one-line' of code. I...

Dashing dashboard won't display on Windows

ruby,curl,sinatra,dashing
I ran exactly the following: dashing new project cd project bundle install && dashing start It listed the "using" output and began the server. Output here. Visiting localhost:3030 resulted in a plain grey web page with nothing on it but the text Try this: curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "text":...

Ruby Sinatra/Postgres - can't connect to heroku database with PG.connect?

ruby,postgresql,heroku,sinatra
I am trying to get a site set up on Heroku using Sinatra and PostgreSQL. It worked locally (connecting to local database), but after pushing it to Heroku and changing my PG.connect to reflect that, I get an Internal Server Error the moment a page tries to access the database....

Displaying a table from MySQL database onto webpage with Ruby Sinatra

mysql,ruby,sinatra
I have a MySQL database that I would like to display its table onto a webpage using Sinatra. I would also like to sort the data based on the column as well. So kind of like content management. Does anyone know a gem or point me in the right direction?

Passing in API Key and Parameters with RestClient

ruby,sinatra
In my application I have a user pass in a form that fires out an API request and then displays the results of the query. I allow the user to to select many or few parameters. The problem I get is a 401 Authorization error and I believe that is...

Can't use conditions on symbols. DataMapper with Sinatra

ruby,sinatra,datamapper
I'm getting troubles when trying to use conditions on symbols in DataMapper: clusters = Cluster.all(:latitude.not => nil) This code throws an error: ArgumentError - condition #<Origin::Key:0x50d05a0 @name=:latitude, @strategy=:__override__, @operator="$not", @expanded=nil, @block= nil> of an unsupported object Origin::Key: C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:888:in `block in assert_valid_conditions' C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:853:in `each'...

How to map routes to controllers in Sinatra?

ruby,model-view-controller,routing,sinatra
I'd like to create a simple experimental MVC framework using Sinatra. I'd like to define resources by name "pages" for example should resolve to: /pages (index) /pages/new /pages/:id/show (show) as WELL as map to app/controllers/PagesController.rb with corresponding get('/') to be responsible for the index, post('/pages/create') be responsible for creation, etc....

order_by in Mongoid along find_by, NoMethodError - undefined method `order_by'

ruby-on-rails,ruby,mongodb,sinatra,mongoid
I have to retrieve the mongodb records in a sinatra app using Mongoid. For this I am trying to order the records retrieved using the following query: @bin = Bin.find_by(bin_id: params[:bin_id]).order_by(:created_at.desc) But I am getting the NoMethodError, NoMethodError - undefined method `order_by' for #<Bin:0x00000101d24d60>: /Users/harshsingh/Documents/Codes/mogreet-requestbin/app.rb:79:in `block in <class:App>' /Users/harshsingh/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'...

How to sign JWT?

ruby,authentication,oauth,sinatra,jwt
I'm trying to secure a Sinatra API. I'm using ruby-jwt to create the JWT, but I don't know exactly what to sign it with. I'm trying to use the user's BCrypt password_digest, but every time password_digest is called it changes, making the signature invalid when I go to verify it....

Routing in Sinatra

ruby,web,routing,sinatra
I have an application where the user fills out a form at /search and I want that to output to /search/results. In my app.rb, I've attempted to call post '/search' do ... erb :search/results end However that fails. My directory structure is: views -search --results But it fails. Where am...

502 Bad gateway error/NameError in Rack application for sinatra app on nginx, passenger in a docker container

nginx,sinatra,docker,passenger
I am starting with docker (1.3.2) and I am trying to get an example working with nginx, passenger and sinatra. Nginx and passenger seem to work. However, I do not get my sinatra app to run. curl localhost gives a 502 bad gateway error and the same when I try...

Only root route works in Sinatra with Passenger/Apache

apache,.htaccess,sinatra,passenger
I have a sinatra app running with Apache/Passenger in a subfolder with the following in an .htaccess file <IfModule mod_passenger.c> Options -MultiViews Allow from all PassengerResolveSymlinksInDocumentRoot on RackEnv development RackBaseURI /myapp PassengerAppRoot /home/username/myapp SetEnv GEM_HOME /mypath/ruby/gems </IfModule> and my Sinatra app has two routes get '/' do 'Root Request' end...

Ruby each loop based on array

ruby,sinatra
I have an array like this: @airports = [ ['Malaysia', 'Alor Setar', 'AOR'], ['Malaysia', 'Bintulu', 'BTU'], ['Malaysia', 'Ipoh', 'IPH'], ['Malaysia', 'Johor Bahru', 'JHB'], ['Indonesia', 'Kuching', 'KCH'], ['Indonesia', 'Labuan', 'LBU'], ['Indonesia', 'Langkawi', 'LGK'], ['Indonesia', 'Miri', 'MYY'], ['Indonesia', 'Penang', 'PEN'], ] then in my view: <select name="from" class="form-control select2"> <% @airports.each do...

Change value of Ruby variable in ERB file upon onlick

ruby,sinatra,erb
I want to change the value of a Ruby local parameter in my .erb file when a user clicks on a bit of text. (I am using Ruby with Sinatra, not Rails). The code looks like this: <div class="modal-body"> <!-- Get ERB to work here --> <p><i>No account? <a href="#"...

Variable containing regex as string/generating regex dynamically and trouble with \b

ruby,regex,sinatra
I have these variables: keywords = ["/(?=.*?\bTest1\b).*/i","/(?=.*?\bTest2\b)(?=.*?\bTest3\b).*(?m)^(?!.*?NotThis4)(?m)^(?!.*?NotThis5).*$/i"] hash = {"Test2 Test3 irrelevant1"=>"Mon, 16 Feb 2015 09:26:02 +0000", "Test2 Test3 NotThis4 irrelevant2"=>"Mon, 16 Feb 2015 09:24:01 +0000", "Test1 irrelevant3 irrelevant4"=>"Mon, 16 Feb 2015 09:23:02 +0000"} I need to run: keywords.each do |regex| hash.select{ |k,_| k[regex]} end I'm trying to collect the...

Ruby Sinatra - How to capture post json data and save to file

ruby,sinatra
How do I capture a Json data from POST route and save it to file? I have simple ruby sinatra code as below. #!/usr/bin/env ruby require 'rubygems' require 'sinatra' require 'json' post '/' do values = JSON.parse(request.env["rack.input"].read) # How do I save "values" of JSON to file.. end ...

DataMapper Self Referential Model

ruby,sinatra,datamapper
I have a model: class Comment include DataMapper::Resource property :id, Serial property :comment, Text, :required => true belongs_to :user belongs_to :lecture has n, :replies, :child_key => [:source_id] has n, :comments, self, :through => :replies, :via => :target end And I want to add a comment as a reply to another,...

How can I make an instance persist across requests in Sinatra?

ruby,gem,sinatra
I'm using Sinatra to build a very simple 'command center' to control various USB devices. I have created classes like class Device and subclassed the various types of devices. The problem is that, I don't want to use a database to store all my information. The list of devices will...

Running Ruby Sinatra inside a Docker container not able to connect (via Mac host) or find commands (in different scenario)?

ruby,sinatra,docker
I've tried two forms of Dockerfile to get a simple Ruby/Sinatra app running, and in both scenarios it fails for different reasons (I'll explain both in a moment). Effectively I want to access the Sinatra web server from my host (Mac OS X using Boot2Docker). The app structure is: ....

Sequel Sinatra Post Database params

ruby,sqlite3,sinatra,sequel
I am trying to build just a very simple form for registering attendees for my wedding. This is somewhat a draft because I don't know if I'll be using Sinatra or Rails. I am going to be setting up scheduled emails to notify guests and myself of the wedding specifics....

using ruby and sinatra, and the Phony gem how can I find the alpha2 code from a phone number?

ruby,sinatra,plivo
I have an international number as a string, so 81312345678 (Japan, Tokyo number) or 85212345678 (Hong Kong) and I need to isolate the country code, 81 in the case of Japan and 852 in the case of Hong Kong, in order to then identify the 2 letter alpha2 code of...

External CSS file not working alongside bootstrap

css,twitter-bootstrap,sinatra
I am trying to add custom styling to my web app. Here is the link to my code: https://github.com/SammyAbukmeil/rps-challenge In layout.erb I have the following: <head> ... <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="css/custom.css"> ... </head> Which should be loading my custom.css file. In views/index.erb I have an ID of...

ActiveSupport TestCase not running in Sinatra

ruby,sinatra,activesupport
I'm setting up a new Sinatra app and am having issues getting my tests to run via a rake task. When I run rake:test, the task runs, shows me which files it will be running, but nothing happens. I know it's loading the class because it has failed due to...

How to decode route parameters in Sinatra?

parameters,routes,sinatra,decode
I have implemented a simple route : get '/test' do params end When I call it without encoded parameters like /test?plip=plop => ["plip", "plop"] I am able to retrieve my parameter without any problem. However, with encoded parameters : /test?plip%3Dplop => ["plip=plop", nil] the key/value does not match anymore. Do...

postgres data to dashing

sinatra,dashing
Is it possible to send data contained in postgres to dashing dashboard? I have found mysql example here and same question here. I edited my job in jobs folder. I have also included pg gem. require 'pg' conn = PGconn.new(:host => "10.10.8.10", :port => "5432",:dbname => "db1",:login => "test",:password =>...

Access Padrino settings from controller

ruby-on-rails,ruby,sinatra,padrino
I am trying to get values from Padrino.configure_apps block in config/apps.rb, but Sinatra way not working here. Anyone know the Padrino way to access the settings from controller ? Thankx in advance!

Sequel: exclude records that do not have associations

ruby,sinatra,sequel
I have a Sinatra app using the Sequel ORM in which I'm trying to list only Categories that have one or more Posts. So, if I have two categories in the database; "Apples" and "Oranges", and one Post assigned to "Apples", then when I list the current categories I only...

Using sinatra checkboxes to filter searching

ruby-on-rails,ruby,twitter,sinatra
search.rb keywords = ["sheffield", "liverpool", "london", "manchester"] get '/search' do @keyword = "No keyword entered" @results = [] puts keywords[0] unless params[:filter].nil? @tick_box1 = params[:filter][:follower] == 'on' @tick_box2 = params[:filter][:following] == 'on' end if (@tick_box1) && (@tick_box2) @results = @client.search('chelsea').take(20) elsif (@tick_box1) && ([email protected]_box2) @results = @client.search('arsenal').take(20) elsif ([email protected]_box1) &&...

Datamapper not saving ID, LocalJumpError - no block given

ruby,sinatra,datamapper,ruby-datamapper
I recently refactored my DataMapper code, slowly rolling it out, and got it working on one database, but now I'm encountering problems when rolling it out to my expense database. Couldn't find the answer anywhere, and I've tried lots of fiddling. I have a form (using Sinatra) that takes several...