sinatra

No such file or directory - getcwd

∥☆過路亽.° 提交于 2019-12-05 09:20:25
问题 I uploaded my Sinatra app to Beanstalk. When I go to my site my logs are returned No such file or directory - getcwd The app was working before. I believe the issue has to do with the fact that I added SASS to my app, but I'm not positive. In my config.ru , I have the following code dealing with SASS... # use scss for stylesheets Sass::Plugin.options[:style] = :compressed use Sass::Plugin::Rack If it could be another issue, let me know and I can provide more information. Thanks. 回答1: Some

error happens when I try “all” method in datamapper

☆樱花仙子☆ 提交于 2019-12-05 09:11:24
When I try to do this in Sinatra, class Comment include DataMapper::Resource property :id, Serial property :body, Text property :created_at, DateTime end get '/show' do comment = Comment.all @comment.each do |comment| "#{comment.body}" end end It returns this error, ERROR: undefined method `bytesize' for #<Comment:0x13a2248> Could anyone point me to the right direction? Thanks, Luke Antins Your getting this error because Sinatra takes the return value of a route and converts it into a string before trying to display it to the client. I suggest you use a view/template to achieve your goal: #

How do I tell Sinatra what environment (development, test, production) it is?

此生再无相见时 提交于 2019-12-05 07:31:05
(Disclaimer: New to deploying Sinatra on Heroku.) I have seen http://www.sinatrarb.com/configuration.html and it tells me to set :environment, :production . My question is, how can I specify it to do: "when in Heroku, set environment as production, else stay in test/development." Also, even after putting the line set :environment, :production , I don't think it is working because when I try to rackup the app locally, it's still running (when I know (or I think I know) that it shouldn't because I haven't installed postgres on my computer). Gemfile group :production do gem 'dm-postgres-adapter'

Sinatra/Ruby default a parameter

荒凉一梦 提交于 2019-12-05 07:06:42
Is there a way to default a parameter in Sinatra? I am currently looking to see if 'start' was passed as a parameter, but it seems a little hacky. It would be nice if I could tell Sinatra to default certain parameters if they are not specified. get '/comments/?' do # want to setup page stuff, default to first page if not specified params[:start] = 0 if !params[:start] end Any ideas? It's true that you can use ||= in this way, but it's a very strange thing to set the params after retrieving them. It's more likely you'll be setting variables from the params. So instead of this: params[:start] ||

Accessing the irb in a modular Sinatra application

孤街醉人 提交于 2019-12-05 06:42:42
问题 I am building an application which subclasses Sinatra like so: require 'rubygems' require 'sinatra/base' require 'sinatra/assetpack' class App < Sinatra::Base ... run! end How can I access irb? Options are not parsed when executing sinatra this way, how do I programmatically open an irb shell? 回答1: I'm a little confused whether you want to open an IRB session from within your app (?) or use IRB to debug your Sinatra project? For debugging Rack-based apps (such as Sinatra), I like using the

How to change the log level in Sinatra

断了今生、忘了曾经 提交于 2019-12-05 06:38:06
I am using this code to enable logging in my Sinatra app: log_file = File.new('my_log_file.log', "a") $stdout.reopen(log_file) $stderr.reopen(log_file) $stdout.sync=true $stderr.sync=true The actual logging is done using: logger.debug("Starting call. Params = #{params.inspect}") It turns out that only INFO or higher level log messages are logged and DEBUG messages are not logged. I am looking for a way to set up the log level to DEBUG. I guess there might be a better way, but you can always do something like setting the log level in a before filter: before do logger.level = 0 end You can set

What's the most commonly used unit testing framework for different types of Ruby applications? [duplicate]

馋奶兔 提交于 2019-12-05 05:41:16
This question already has an answer here: What is the community-preferred Ruby unit testing framework? 4 answers Are the same unit testing frameworks used for different web frameworks - Rails, Merb, Sinatra, Ramaze and desktop frameworks - Shoes? And what is the most widely used unit testing framework that would work with all of the various web and desktop frameworks? TestUnit is based on JUnit, and so there is port to most languages. This is probably the most ubiquitous. Behavior driven testing has yielded tools like RSpec, and it seems like right now that may be the most popular test

Displaying Error Message with Sinatra

◇◆丶佛笑我妖孽 提交于 2019-12-05 05:36:53
I'm writing a simple app that takes standard input from the user. As for the email entry, I have it verify if it is in a standard email format and then have it list the problems like this when a new instance is going to be saved: u = User.new u.email = params[:email] u.save if u.save redirect '/' else u.errors.each do |e| puts e end end I know that if it is correct it should return back to the home page. If it is wrong I want it to return to the home page as well, but I want it to return an error value (so I can have a pop-up or just something onscreen letting the user know that the format of

alias url with sinatra / padrino

让人想犯罪 __ 提交于 2019-12-05 04:57:30
问题 I've this and it works get :about, :map => '/about_us' do render :erb, "<%= 'foo' %>" end get '/:slug' do redirect "/about_us" # <-- end Is possible to do in some way "render" instead of "redirect"? or something like render 'posts/1' 回答1: get :about, :map => '/about_us' do render :erb, "<%= 'foo' %>" end get '/:slug' do call env.merge('PATH_INFO' => '/about_us') end 来源: https://stackoverflow.com/questions/3384134/alias-url-with-sinatra-padrino

Creating a route with Sinatra to only accept a certain Content-type

孤者浪人 提交于 2019-12-05 04:48:20
I'm trying to create a route with Sinatra that only accepts POST with an Content-type: application/json without success. My approach is as follows: post '/dogs', :provides => :json do # returns here a json response end Testing with curl, I have seen that :provides => :json configures the route to respond with an Content-Type: application/json . That's right because I want also to respond with a JSON message to the POST request but I really need that this route only respond to POST requests with a Content-Type: application/json and not, for example, to others (e.g. Content-Type: application/xml