sinatra

How to pass an argument when calling a view file?

柔情痞子 提交于 2019-12-31 12:07:26
问题 I wrote a webform using Sinatra and Haml that will be used to call a Ruby script. Everything seems fine except for one thing: I need to pass an argument to a Haml view file from the Sinatra/Ruby script. Here is a part of my code: #!/usr/bin/env ruby require 'rubygems' require 'sinatra' require 'haml' get '/' do haml :index end post '/' do name = params[:name] vlan = params[:vlan] tmp = nil tmp = %x[./wco-hosts.rb -a -n #{name} -v #{vlan}] if tmp.include?("Error") haml :fail else haml :success

Access Ruby hash variables

人走茶凉 提交于 2019-12-31 10:41:40
问题 I am pretty new to ruby and sinatra but basically I have this route: put '/user_list/:user_id' do puts request.params["model"] end and it returns the following {"password":"36494092d7d5682666ac04f62d624141","username":"nicholas","user_id":106,"firstname":"Nicholas","email":"nicholas@macpractice.com","is_admin":0,"lastname":"Rose","privileges":""} I am now having a hard time accessing values of each of those. It doesn't really seem to be in hash format so I can't really do request.params[

Styling a sudoku grid

隐身守侯 提交于 2019-12-31 04:15:07
问题 I’ve created a sudoku puzzle creator / solver and need a bit of help with some CSS to style it. Typically they are styled like this: . Some naming I’m using. Cell - each individual cell which contains a single number. Box - one of the 9 boxes each containing 3 x 3 cells Grid - the entire 9x9 playing area. My html is partially generated by my ruby / Sinatra app (at least the repeating DIV’s are) and structured as such : #game { margin-left: auto; margin-right: auto; width: 360px; } .cell input

reading parameters on Sinatra post

China☆狼群 提交于 2019-12-31 03:19:08
问题 I'm working on my first Sinatra app and I have an hard time getting parameters from a post request. I'm using MiniTest::Spec and my spec looks like payload = File.read("./spec/support/fixtures/payload.json") post "/api/v1/verify_payload", { payload: payload }, { "CONTENT_TYPE" => "application/json" } last_response.body.must_eql payload And this is my route namespace '/api/v1' do post '/verify_payload' do MultiJson.load(params[:payload]) end end The spec fails because last_response.body is

Error when starting Sinatra: “tried to create Proc object without a block”

瘦欲@ 提交于 2019-12-31 01:44:06
问题 I am very new to ruby / rails and have an issue that I have not been able to figure out but feel it should be relatively simple to fix. Command: ruby app.rb Error: /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1144:in `define_method': tried to create Proc object without a block (ArgumentError) from /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1144:in `compile!' from /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1129:in `route' from /Library

Error when starting Sinatra: “tried to create Proc object without a block”

谁都会走 提交于 2019-12-31 01:44:03
问题 I am very new to ruby / rails and have an issue that I have not been able to figure out but feel it should be relatively simple to fix. Command: ruby app.rb Error: /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1144:in `define_method': tried to create Proc object without a block (ArgumentError) from /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1144:in `compile!' from /Library/Ruby/Gems/1.8/gems/sinatra-1.2.5/lib/sinatra/base.rb:1129:in `route' from /Library

Parsing LESS options in a Sinatra app

谁说我不能喝 提交于 2019-12-30 07:31:39
问题 I'm having trouble changing the path that LESS uses to include imports. My routes file has get "/css/main.css" do less :main, :paths => ["public/css"] end However, if I include an external less file with @import in my stylesheet the LESS compiler cannot find the file. I've placed a copy in both the views path and public/css directories, but it still can't find it. It CAN however find plain .css files in public\css . 回答1: I hit this today, and was able to solve it like so: require 'less'

Heroku push rejected

别说谁变了你拦得住时间么 提交于 2019-12-30 05:25:07
问题 -----> Ruby/Rack app detected -----> Using Ruby version: ruby-1.9.3 -----> Installing dependencies using Bundler version 1.3.0.pre.2 Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ Fetching gem metadata from http://rubygems.org/......... Fetching gem metadata from http://rubygems.org/.. ^[[C^[[D^[[D/app/slug-compiler/lib/utils.rb:66:in `block (2 levels) in spawn': command='/app/slug-compiler/lib/../../tmp/buildpacks/ruby/bin/compile /tmp/build

Capistrano asks for password when deploying, despite SSH keys

雨燕双飞 提交于 2019-12-29 10:13:51
问题 My ssh keys are definitely set up correctly, as I'm never prompted for the password when using ssh. But capistrano still asks for a password when deploying with cap deploy . It doesn't ask for the password when I setup with cap deploy:setup though, strangely enough. It would make the deployment cycle so much smoother without a password prompt. Specifics: I'm deploying a Sinatra app to a Dreamhost shared account (which uses Passenger). I had followed a tutorial for doing so long back, which

Sinatra and question mark

依然范特西╮ 提交于 2019-12-29 07:32:09
问题 I need to make some methods with Sinatra that should look like: http//:localhost:1234/add?string_to_add But when I declare it like this: get "/add?:string_to_add" do ... end it doesn't see the string_to_add param. How should I declare my method and use this parameter to make things work? 回答1: In a URL, a question mark separates the path part from the query part. The query part normally consists of name/value pairs, and is often constructed by a web browser to match the data a user has entered