sinatra

Access Ruby hash variables

心已入冬 提交于 2019-12-02 22:09:57
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["model"][:password] It just returns nil.. I just need to know what I can do to access those variables, or

How to pass an argument when calling a view file?

耗尽温柔 提交于 2019-12-02 20:29:01
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 end end If the script encounters an arror it will return a string including the word "Error". If this

Sinatra success stories [closed]

蹲街弑〆低调 提交于 2019-12-02 18:07:47
Have you used Sinatra successfully? What kind of a project was it? In what situations would you recommend using Sinatra instead of Rails or Merb? JW. I've dabbled with Sinatra, but haven't really written anything serious with it. As you said above, there's a list at http://www.sinatrarb.com/wild.html , although a lot of the applications listed there seem to link to GitHub pages, which I assume are often people experimenting with Sinatra and publishing their results online. Then, there's also the Sinatra mailing list , where you might find links to some interesting projects.[*] As for your

Best way to cache a response in Sinatra?

…衆ロ難τιáo~ 提交于 2019-12-02 17:46:18
I'm building a simple app on the side using an API I made with Sinatra that returns some JSON. It's quite a bit of JSON, my app's API relies on a few hundred requests to other APIs. I can probably cache the results for 5 days or so, no problem with the data at all. I'm just not 100% sure how to implement the caching. How would I go about doing that with Sinatra? Personally, I prefer to use redis for this type of things over memcached. I have an app that I use redis in pretty extensively, using it in a similar way to what you described. If I make a call that is not cached, page load time is

How to render a partial in sinatra view (haml in haml)?

送分小仙女□ 提交于 2019-12-02 17:37:29
I have a simple sinatra app that uses haml and sass for the views. One of the views (located in the views folder) is a partial for my navigation menu. I am trying to render it from index.haml but I get the following error: wrong number of arguments (1 for 2) I am trying to render it with the following lines in index.haml .navigation = render :partial => "nav" kfl62 EDIT: !!! OUTDATED !!! Read Jason's answer below! What are you trying works in rails ! Sinatra has no partial method. An implementation of partial on Sinatra looks like this (source gist) from github: module Haml module Helpers def

Posting JSON params from java to sinatra service

雨燕双飞 提交于 2019-12-02 17:21:29
问题 I have an android app posting to my sinatra service. Earlier I was not able to read parameters on my sinatra service. However, after I set content type to "x-www-form-urlencoded". I was able to see params but not quite how I wanted. I am getting something this as my params of the request at my sinatra service. {"{\"user\":{\"gender\":\"female\"},\"session_id\":\"7a13fd20-9ad9-45c2-b308- 8f390b4747f8\"}"=> nil, "splat"=>["update_profile.json"], "captures"=>["update_profile.json"]} This is how

Contact form in ruby, sinatra, and haml

試著忘記壹切 提交于 2019-12-02 16:45:53
I'm new to all three, and I'm trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with it (due to my inexperience with sinatra). Any help at getting this working would be appreciated, I can't seem to figure out/find the documentation for this sort of thing. haml code from the contact page: %form{:name => "email", :id => "email", :action => "/contact", :method => "post", :enctype => "text/plain"} %fieldset %ol %li %label{:for => "message[name]"} Name: %input{:type => "text", :name => "message[name]", :class =

What are the main differences between Sinatra and Ramaze?

人盡茶涼 提交于 2019-12-02 15:38:55
I'm looking for a lightweight Ruby web framework and have come across Sinatra and Ramaze . Both seem extemely light, concise and simple. But I don't know enough about either to say what the main distinctions are. Perhaps someone with experience with one or both of these could comment? Sinatra does not enforce MVC. Dave Everitt Other lightweight Ruby frameworks I like _why's Camping (now maintained by the community ) which has to be the lightest of them all (for recent info [>= v1.9] see the Camping links on the Camping wiki , Eleanor McHughe's ' Going off the Rails ' or [v 1.5] Jeremy McAnally

Why Sinatra request takes EM thread?

不问归期 提交于 2019-12-02 14:06:53
问题 Sinatra app receives requests for long running tasks and EM.defer them, launching them in EM's internal pool of 20 threads. When there are more than 20 EM.defer running, they are stored in EM's threadqueue by EM.defer. However, it seems Sinatra won't service any requests until there is an EM thread available to handle them. My question is, isn't Sinatra suppose to use the reactor of the main thread to service all requests? Why am I seeing an add on the threadqueue when I make a new request?

What is a very simple authentication scheme for Sinatra/Rack

大憨熊 提交于 2019-12-02 13:56:59
I am busy porting a very small web app from ASP.NET MVC 2 to Ruby/Sinatra. In the MVC app, FormsAuthentication.SetAuthCookie was being used to set a persistent cookie when the users login was validated correctly against the database. I was wondering what the equivalent of Forms Authentication would be in Sinatra? All the authentication frameworks seem very bulky and not really what I'm looking for. Here is a very simple authentication scheme for Sinatra. I’ll explain how it works below. class App < Sinatra::Base set :sessions => true register do def auth (type) condition do redirect "/login"