Search Results

Search found 196 results on 8 pages for 'sinatra'.

Page 4/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • How to specify custom Sass directory with sinatra

    - by yaya3
    Instead of serving my Sass files from the default 'views' directory I'd like to change this to /assets/sass The following attempts are in my main ruby root file in the app: Attempt 1 set :sass, Proc.new { File.join(root, "assets/sass") } get '/stylesheet.css' do sass :core end With this I get the following error: myapp.rb:17 NoMethodError: undefined method `merge' for "/Users/x/x/x/mysinatraapp/assets/sass":String Attempt 2 get '/stylesheet.css' do sass :'/assets/sass/core' end Attempt 3 get '/stylesheet.css' do sass :'/assets/sass/core' end Both return the following error: Errno::ENOENT: No such file or directory - ./views/assets/sass/core.sass Attempt 4 get '/stylesheet.css' do sass :'../assets/sass/core' end This works! however, there must be something along the lines of set :sass, Proc.new { File.join(root, "assets/sass") } that sets this up for me?

    Read the article

  • Sinatra Routing Exceptions

    - by Ethan Turkeltaub
    I want to be able to do the following: get '/:slug' do haml :page end get '/administration' do haml :admin end Is there a way that I can have get '/:slug' do have an exception for /administration? I realize you can do this with if else statements: get '/:slug' do if params[:slug] == 'administration' haml :admin else haml :page end end But that isn't very clean looking. Is there a way to have an exception to routes?

    Read the article

  • Run Sinatra via a Rake Task to Generate Static Files?

    - by viatropos
    I'm not sure I can put this correctly but I'll give it a shot. I want to use Sinatra to generate static html files once I am ready to deploy an application, so the resulting final website would be pure static HTML. During development, however, I want everything to be dynamic so I can use Haml and straight Ruby code to make things fast/dry/clear. I don't want to use Jekyll or some of the other static site generators out there because they don't have as much power as Sinatra. So all I basically need to be able to do is run a rake task such as: rake sinatra:generate_static_files. That would run the render commands for Haml and everything else, and the result would be written to files. My question is, how do I do that with Sinatra in a Rake task? Can I do it in a Rake task? The problem is, I don't know how to include the Sinatra::Application in the rake task... The only other way I could think of doing it is using net/http to access a URL that does all of that, but that seems like overkill. Any ideas how on to solve this?

    Read the article

  • In Sinatra, best way to serve iPhone layout vs. normal layout?

    - by Doug
    I'm writing a Sinatra app which needs to render different layouts based on whether the user is using an iPhone or a regular browser. I can detect the browser type using Rack-Mobile-Detect but I'm not sure of the best way to tell Sinatra which layout to use. Also, I have a feeling that how I choose to do this may also break page caching. Is that true? Example code: require 'sinatra/base' require 'haml' require 'rack/mobile-detect' class Orca < Sinatra::Base use Rack::MobileDetect helpers do def choose_layout if request.env['X_MOBILE_DEVICE'] == :iPhone # use iPhone layout else # use normal layout end end end before do # should I use a before filter? choose_layout() end get '/' do haml :home # with proper layout end end #Class Orca

    Read the article

  • From Sinatra Base object. Get port of application including the base object

    - by Poul
    I have a Sinatra::Base object that I would like to include in all of my web apps. In that base class I have the configure method which is called on start-up. I would like that configure code to 'register' that service with a centralized database. The information that needs to be sent when registering is the information on how to contact this web-service... things like host and port. I then plan on having a monitoring service that will spin over all registered services and occasionally ping them to make sure they are still up and running. In the configure method I am having trouble getting the port information. The 'self.settings.port' variable doesn't seem to work in this method. a) any ideas on how to get the port? I have the host. b) is there a sinatra plug-in that already does something like this so I don't have to write it myself? :-) //in my Sinatra::Base code. lets call it register_me.rb RegisterMe < Sinatra::Base configure do //save host and port information to database end get '/check_status' //return status end //in my web service code require register_me //at this point, sinatra will initialize the RegisterMe object and call configure post ('/blah') //example of a method for this particular web service end

    Read the article

  • Can you let users upload Sinatra apps and run them inside Rails as middleware?

    - by Brian Armstrong
    I want to let users write small custom apps (think themes or plugins on Wordpress) and upload/run them on my site. I'm thinking about using Sinatra apps for this since it would give the users a lot of flexibility, and then running them as middleware inside my rails app. But I can't figure out the security implications of this. I tried creating a simple sinatra app as middleware, and it has access to all the rails models and everything - so that is bad. Is there a way for rack to keep these separate so that the sinatra apps are effectively sandboxed and can't do any bad things (outside of an API or some specific way I setup for them to communicate)? There may be an easier way to accomplish this that I haven't thought of too, so ideas welcome. Thanks!

    Read the article

  • In Sinatra, how can I serve static index.html files in subdirectories in public folder?

    - by socrateos
    I noticed that Sinatra does not recognize index.html files in public folder's subdirectories and returns an error when url is pointing to a directory without specifiying the file name. For example, if user enters a url like "www.mydomain.com/subdiretory/", Sinatra fails to recognize the existence of an index.html file in that directory. There are hundreds of subdirectories in my public folder so that it is impossible to specify each one of them in code (and the number of subdirectories keeps growing). How can I tell Sinatra to leave my web server (Apache) alone (to server index.html file) if there is an index.html file in a subdirectory of public folder when url is pointing to that directory without the file name?

    Read the article

  • How can I get all the checked items from a submitted form with sinatra's params?

    - by 102405176597896213397
    I'm running Sinatra 1.0 with HAML, my form has a number of checkboxes, for example books I like, and you would select all the books you want. The checkbox name is "books". In sinatra params['books'] there should be an array of all the books that were checked, but it only has the last item that was checked, not an array. How can I get all the checked items? HAML: %form{:action => "/test", :method => 'post'} %input{:name=>'check',:type=>'checkbox',:value=>'item1'} item 1 %input{:name=>'check',:type=>'checkbox',:value=>'item2'} item 2 %input{:name=>'check',:type=>'checkbox',:value=>'item3'} item 3 %input{:type => "submit", :value => "send", :class => "button"} Sinatra get method post '/test' do puts params['check'] #should be an array but is last item checked end

    Read the article

  • What is a better way to convert a simple sinatra app to static html pages?

    - by dimus
    A friend of mine asked to create a static website and I found that making such site using Sinatra is a pure joy. I just wrote all my routes like this: get '/index.html' do haml :index end get '/app.css' do sass :app end .... So I was able to use layouts, and haml and sass to put site together quickly. To create the static site I used wget -r -l2 http://localhost:4567 Which did work pretty well, but I imagine there is a better way to create a static site from a Sinatra code?

    Read the article

  • How to do a Post/Redirect/Get using Sinatra?

    - by John Topley
    What's Sinatra's equivalent of Rails' redirect_to method? I need to follow a Post/Redirect/Get flow for a form submission whilst preserving the instance variables that are passed to my view. Does the redirect method preserve them? (I'm at work at the moment and don't have access to Sinatra to try for myself.)

    Read the article

  • How do I pass a cookie to a Sinatra app using curl?

    - by Brandon Toone
    I'm using the code from the example titled "A Slightly Bigger Example" from this tutorial http://rubylearning.com/blog/2009/09/30/cookie-based-sessions-in-sinatra/ to figure out how to send a cookie to a Sinatra application but I can't figure out how to set the values correctly When I set the name to be "brandon" in the application it creates a cookie with a value of BAh7BiIJdXNlciIMYnJhbmRvbg%3D%3D%0A which is a url encoding (http://ostermiller.org/calc/encode.html) of the value BAh7BiIJdXNlciIMYnJhbmRvbg== Using that value I can send a cookie to the app correctly curl -b "rack.session=BAh7BiIJdXNlciIMYnJhbmRvbg==" localhost:9393 I'm pretty sure that value is a base64 encoding of the ruby hash for the session since the docs (http://rack.rubyforge.org/doc/classes/Rack/Session/Cookie.html) say The session is a Ruby Hash stored as base64 encoded marshalled data set to :key (default: rack.session). I thought that meant all I had to do was base64 encode {"user"=>"brandon"} and use it in the curl command. Unfortunately that creates a different value than BAh7BiIJdXNlciIMYnJhbmRvbg==. Next I tried taking the base64 encoded value and decoding it at various base64 decoders online but that results in strange characters (a box symbol and others) so I don't know how to recreate the value to even encode it. So my question is do you know what characters/format I need to get the proper base64 encoding and/or do you know of another way to pass a value using curl such that it will register as a proper cookie for a Sinatra app?

    Read the article

  • Ubuntu - Ruby Daemon script creates two processes - sh and ruby - PID file points at sh, not ruby

    - by Jonathan Scoles
    The PID file for a ruby process I have running as a daemon is getting the wrong PID. It appears that running /etc/init.d/sinatra start creates two processes - sh and ruby, and the PID that ends up in the PID file is that of the sh process. This means that when I then run /etc/init.d/sinatra stop or /etc/init.d/sinatra restart, it is killing sh and leaving the ruby process still running. I'd like to know a) why is my script launching two processes - sh and ruby, and not just ruby, and b) how do I fix it to just launch ruby? Details of the setup: I have a small Sinatra server set up on an ubuntu server, running as a daemon. It is set to automatically at server startup run a script named sinatra in /etc/init.d that launches the a control script control.rb, which then runs a ruby daemon command to start the server. The script is run under the 'sinatrauser' account, which has permissions for the directories the script needs. contents of /etc/init.d/sinatra #!/bin/bash # sinatra Startup script for Sinatra server. sudo -u sinatrauser ruby /var/www/sinatra/control.rb $1 RETVAL=$? exit $RETVAL To install this script, I simply copied it to /etc/init.d/ and ran sudo update-rc.d sinatra defaults contents of /var/www/sinatra/control.rb require 'rubygems' require 'daemons' pwd = Dir.pwd Daemons.run_proc('sinatraserver.rb', {:dir_mode => :normal, :dir => "/opt/pids/sinatra"}) do Dir.chdir(pwd) exec 'ruby /var/www/sinatra/sintraserver.rb >> /var/log/sinatra/sinatraOutput.log 2>&1' end portion of output from ps -A 6967 ? 00:00:00 apache2 10181 ? 00:00:00 sh <--- PID file gets this PID 10182 ? 00:00:02 ruby <--- Actual ruby process running Sinatra 12172 ? 00:00:00 sshd The PID file gets created in /opt/pids/sinatra/sinatraserver.rb.pid, and always contains the PID of the sh instance, which is always one less than the PID of the ruby process EDIT: I tried micke's solution, but it had no effect on the behavior I am seeing. This is the output from ps -A f. This output looks the same whether I use sudo -u sinatrauser ... or su sinatrauser -c ... in the service start script in /etc/init.d. 1146 ? S 0:00 sh -c ruby /var/www/sinatra/sinatraserver.rb >> /var/log/sinatra/sinatraOutput.log 2>&1 1147 ? S 0:00 \_ ruby /var/www/sinatra/sinatraserver.rb

    Read the article

  • How can I set up jnlp for use with Sinatra?

    - by mmr
    I have a website currently running Sinatra and a bunch of other technologies. I wanted to get progress bars running, but that's been a no go. So, a friend of mine whipped up a quick upload in Java, and I'm running that through scponly (chrooted) to make sure they can't do anything funny with changing directories and suchlike. But how can I start the jnlp file from Sinatra? Is it as simply as making it a link and then letting it be downloaded by the user? This code suggests otherwise, but there are a lot of things in there I don't understand (probably because I'm not reading it in the context of the larger program there).

    Read the article

  • Can I have sinatra not read the entire request body into memory?

    - by Chris Markle
    Say I have a sinatra route ala: put '/data' do request.body.read [...] end It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/sinatra beforehand? I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand. put '/data' do while request.body.read(1024) != nil [...] end [...] end

    Read the article

  • How can I delete a file in Sinatra after it has been sent via send_file?

    - by John Reilly
    I have a simple sinatra application that needs to generate a file (via an external process), send that file to the browser, and finally, delete the file from the filesystem. Something along these lines: class MyApp < Sinatra::Base get '/generate-file' do # calls out to an external process, # and returns the path to the generated file file_path = generate_the_file() # send the file to the browser send_file(file_path) # remove the generated file, so we don't # completely fill up the filesystem. File.delete(file_path) # File.delete is never called. end end It seems, however, that the send_file call completes the request, and any code after it does not get run. Is there some way to ensure that the generated file is cleaned up after it has been successfully sent to the browser? Or will I need to resort to a cron job running a cleanup script on some interval?

    Read the article

  • Can I have Sinatra / Rack not read the entire request body into memory?

    - by Chris Markle
    Say I have a Sinatra route ala: put '/data' do request.body.read # ... end It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/Sinatra beforehand? I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand. put '/data' do while request.body.read(1024) != nil # ... end # ... end

    Read the article

  • how to pass instance variables between handlers (routes) in sinatra (without flash, sessions, class variable or db)?

    - by jj_
    Say you have: get '/' do haml :index end get '/form' do haml :form end post '/form' do @message = params[:message] redirect to ('/') --- how to pass @message here? end I'd like the @message instance variable to be available (passed to) in "/" action as well, so I can show it in haml view. How can I do that without using session, flash, a @@class_variable, or db persistence ? I'd simply like to pass values as if I was working with passing values between methods. I don't want to use session cookies because user could have them turned off, I don't like it being a class variable which is exposed to all code, and I don't need to overhead of a db. Thanks edit: This is another question explaining a very easy way to deal with this in rails Passing parameters in rails redirect_to This is some more info i gathered around from forums. The following works for rails, i've tried it in Sinatra but no luck, but please try it, maybe I did something wrong, I don't know, and if this code help someone come up with a new idea, please share it If you are redirecting to action2 at the end of action1, just append the value to the end of the redirect: my_var = <some logic> redirect_to :action => 'action2', :my_var => my_var on the same thread another user proposes the folowing: def action1 redirect_to :action => 'action2', :value => params[:current_varaible] end def action2 puts params[:value].inspect end source: http://www.ruby-forum.com/topic/134953 Can something like this work in Sinatra? Thanks

    Read the article

  • Splitting up a Rails/Ruby app onto multiple servers

    - by craig.kaminsky
    We recently moved a large application to two machines, both running the same codebase. I. Machine A Web server for public facing application Receives web hook call backs from our ESP Handles a few large, list-processing jobs (uploaded spreadsheets with data) II. Machine B Manages a massive set of (background) jobs but, primarily, focuses on building and assembling newsletters Runs all integration with our NetSuite platform Runs all system maintenance (read: DB) jobs To me, having these two apps running the same codebase (a large, monolithic Rails application) seems 'wrong'. I am wondering if anyone has advice on how to better break up the code for these two apps. While they both need the same DB and, ultimately, the same model code, Machine B has no need for Controllers and Views and it feels wasteful running a full-stack Rails app for its tasks. A couple things came to mind but I'm not sure if I'm trying to solve a problem that doesn't exist: Break the models out into a sub-module on git and include into both apps Build out the Mahcine B app in plain Ruby or a lighter framework like Sinatra (where I could use ActiveRecord with Sinatra in combo with a sub-module for the model folder). I'm new to this scenario and appreciate any and all feedback or direction! Thank you.

    Read the article

  • Error message when running a Sinatra application on Windows Vista.

    - by Adam Siddhi
    I was following a video tutorial by Adam Keys about how to make a URL shortener app in Sinatra. The code that is giving me problems is located here http://pastie.org/958644 So when I ran it I got this error: shortener.rb:12: syntax error, unexpected $undefined, expecting $end @@ home I typed it exactly as Adam said but this keeps happening. What could the issue be? By the way, I am running ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] on Windows Vista. Thanks, Adam

    Read the article

  • What is the easiest way to get an embedded upload progress bar using Ruby/Sinatra/Haml/Passenger/ngi

    - by mmr
    I have a website where people can upload 30+mb of data in a single block, and I want to be able to show them the progress of their upload without causing the web page to become unresponsive, similar to how flash uploads work in gmail. There's this question here, but I don't know if that progress bar is embedded in the page or if it's using the browser's progress bar. I'm also a bit of a web newb, so I'm not sure if it's the 'easiest'. I asked the swfupload guys how to do this here, and the answer I got is 'this tool requires some knowledge to use it' without giving me much help in figuring out where to get started. I also asked this question on ServerFault, and got no response, so maybe that was the wrong place to ask. I'm all for learning new things and so forth, but there are a lot of potential pathways to take here. Where should I start, and what do I need to know to make everything work with sinatra, haml, ruby, passenger, and nginx? Thanks!

    Read the article

  • Sinatra as backend (API) for Rails app or padrino or any hybrid solution?

    - by JVK
    Is it a good idea to build backend APIs in Sinatra for Rails app. Or is it better to use Padrino? I want to have my backend provides API as service, so that anytime, if I have to develop same app for any client, I can use that back-end API (web services). What is the best approach? My goal is to expose back-end as web services and even rails uses it for webapp. What are the disadvantages or advantage of different approaches?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >