sinatra

Making a post request from a sinatra app to a rails app

我与影子孤独终老i 提交于 2019-12-11 08:16:40
问题 I need to send a POST request from a sinatra app to a rails app which would return back some json. Im testing this functionality locally. The urls are as follows: Rails app : railsapp.mydomain.com/api/v1.json Sinatra app: sinatraapp.mydomain.com On localhost, the urls are: Rails app: localhost:3000/api/v1.json Sinatra app:localhost 3001 In my sinatra app running locally, i have the following code to make the POST request locally $("#submit").click(function(){ $.post("http://localhost:3000/api

Chart.js line 2686 Error

旧城冷巷雨未停 提交于 2019-12-11 07:43:41
问题 I want lineChart of Chart.js in my sinatra application. But firefox console says `TypeError:this.scale is undefined(Chart.js:2686)` and, lineChart is not displayed.I wrote following code. @hello.erb <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script src="Chartjs/Chart.js" type="text/javascript"></script> <script src="script.js" type="text/javascript"></script> </head> <body> <canvas id="line" height="450" width="600

Deploy Sinatra template on Helicon Zoo

前提是你 提交于 2019-12-11 06:56:29
问题 I installed the Ruby Hosting Package and Sinatra on Windows Server 2008R2 with IIS using Helicon Zoo. I downloaded and imported the Sinatra template from Helicon Zoo Templates using web deploy on IIS Now I get this error when navigating to the website: [tid-7800168] paths need to start with / (ArgumentError) C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/urlmap.rb:30:in `block in remap' C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/urlmap.rb:22:in `each' C:/Ruby19/lib/ruby

Sinatra: Template engine not found: prawn

会有一股神秘感。 提交于 2019-12-11 05:57:10
问题 I'm a newbie with Sinatra and prawn. I succeeded with erb and xmm/builder templates. Now trying to get pdf generation with prawn working. Error received: Template engine not found: prawn Code: require 'rubygems' require 'sinatra' require 'sinatra/prawn' set :prawn, { :page_layout => :portrait } get '/pdf' do content_type 'application/pdf' prawn :pdf1 end Thanks. 回答1: Found it: The gem from sbfaulkner doesn't work with current version of Sinatra. Fix: install the forked gem from

How can I view a list of my files in a directory on sinatra?

人盡茶涼 提交于 2019-12-11 05:29:39
问题 I run an project on Sinatra, now it has a lot of files a sub-directories, so I want to view a list of those files with their respective directory. For example, I put in the address bar "localhost:4567/landing/" where landing is the container of some pages, but it throw me this "Sinatra doesn’t know this ditty." Is there a way to do that. I hope you understand what I'm asking. 回答1: Sinatra doesn't deal with the local file system, it deals with HTTP routes. For example, the '/' in get '/' do

How to limit character/word count on database string value in Sinatra/Active Record?

我是研究僧i 提交于 2019-12-11 05:13:55
问题 I have a column in my ActiveRecord database that I want to have a certain word limit. Essentially, I've created a form that allows users to enter text(string). I want to limit the amount of characters that are allowed in that string. @allposts = Post.limit(20) This is what I have so far in the get method for the /current page that posts all of content. 20 = number of posts shown. I also have a /new page where users will post new content. 回答1: You can limit the number of characters in a few

Any way to avoid haml code duplication without creating new file?

删除回忆录丶 提交于 2019-12-11 04:34:26
问题 I have the following code in a .haml template file in a Sinatra app: - if(@order == 'inverse') - @list.reverse_each do |item| .item %span.action-move(data-icon="o") .detail.title=item[0] .detail.content=item[1] %span.action-delete(data-icon="d") - else - @list.each do |item| .item %span.action-move(data-icon="o") .detail.title=item[0] .detail.content=item[1] %span.action-delete(data-icon="d") As you can see, 5 lines of code are identical. Is there a way that I can refactor this code to avoid

Can I test that a Sinatra post method successfully saves to a YAML store?

人盡茶涼 提交于 2019-12-11 04:13:23
问题 I can't find a basic explanation anywhere about how I can test, with Rack::Test, that a Ruby/Sinatra post method successfully saves data to a YAML store/file. (This explains testing get , which I can do(!), but not post ; other mentions of testing post methods with rack/test seem irrelevant.) For self-study, I'm building a "to do" app in Ruby/Sinatra and I'm trying to use TDD everything and unit test like a good little boy. A requirement I have is: When a user posts a new task, it is saved in

How can I pass data to websocket-rack from a class in my sinatra app?

你。 提交于 2019-12-11 03:07:08
问题 I've got a working configuration of websocket-rack in a sinatra app that is intended for a physical installation with multiple screens. There is functionality working where messages are getting passed back and forth through the websockets just fine. My problem is this: I have one page with a standard web form (i.e. not a websocket form), and my goal is to collect the params from that form, turn the params into a string variable, then send the contents of that variable (a string) to a

How to load forked github repo as gem in sinatra/rack application

穿精又带淫゛_ 提交于 2019-12-11 02:48:29
问题 I'm trying to use a gem called "rbing" but there is an issue with it and the project has been abandoned but someone made a fix in a repo so I decided to use bundler to specify the new version. gem "rbing", :git => "https://github.com/KellyMahan/rbing.git" It even installed correctly when I ran bundle install, but inside my Gemfile RubyMine is complaining that "The gem with the specified version requirements isn't available inside SDK RVM: ruby-2.0.0" And it doesn't show up in my external