Hi guys I am trying to learn the sinatra framework and would like to use it as the backend for simple web services. I am also attempting to get my hands dirty with no-sequel solutions and for some reasons decided to learn to work with redis. As for the ruby library to be used I have selected Ohm since it seems like a minimal, no fuss library that I could easily use.
However, looking around and researching, I cannot find sample implementation where there is pagination for Ohm. I have also read a bit and redis and I know that you can specify ranges in the query. The question is, how do I use this with the Ohm ruby library?
Any help or any guide would be greatly appreciated.
Last time I wanted that combination I found this here: https://github.com/sinefunc/pagination
Otherwise use https://github.com/mislav/will_paginate whcih will not work with ohm though but you can use datamapper with redis.
If you want to use mongodb you could use mongomapper which has pagination built in but then that is a completely different situation.
Related
Does anybody know a good data driven development framework/library/gem for Ruby? I know a ton for Rails but I couldn't find anything for Ruby itself. I have a standalone Ruby app and I want to generate test data and write test cases for different data sets. I don't want to use fixtures. Any suggestions?
You mean something like machinist? The readme mentions it can work without Rails.
I don't really plan on using active record or any of the built in database constructs native to CodeIgniter for database access. I have Oracle, SQL Server, and others. I want to use PHP PDO (unless anyone thinks that's bad) because of the universal aspect of it.
I mainly want CI because of some of the built in libraries and MVC. I also like that it is small and easy to work with.
2.x if it matters.
I did see other questions but none exactly about databases.
Thanks.
edit: It's not that I don't think CI and PHP can take it with large websites. This is solely about using multiple databases of varying companies. I have mostly seen MySQL used with it. I know I can use other databases but again, I don't know if it is more trouble than worth or what.
MySQL is the default just because of how widely-adopted it is, especially in the PHP world. Almost everyone has a *AMP stack to work on so it ends up being the main driver used in almost every example out there.
If you're not planning on using the database class, then it really doesn't matter what type of database you are using, just don't load the class. You can still use routing, helpers, libraries, and other CI features.
So yes, I do think it is suitable for your purposes.
CodeIgniter was built with the idea of being the framework closest to native PHP that doesn't tell you what to do. The entire framework is modular and you are not required to use any single component.
Yes, it is absolutely suited to what you are doing. You can plug and play whatever DB driver you want and CI will not complain one bit.
I think CI is more suited for this role than any other of the 'big' frameworks.
I need to build a simple app in a browser:
The interface will be build by javascript and the data will be get/set to the server by the browser
ORMs are not intrinsically linked to MVC frameworks, so feel free to just use ActiveRecord, DataMapper etc. for your app without using a full-fledged framework. If you look around a bit you'll find several blog posts on this topic, e.g.
http://dmathieu.com/en/ruby/ruby-use-active-record-without-rails
Consider combining Sinatra and Sequel. You might also find the Github Services interesting as an example app that uses Sinatra.
I'm just starting to learn my way around CouchDB and Sinatra, but am struggling to find some basic examples of integrating the two via CouchRest. The CouchRest docs assume a little too much to be useful to me yet.
Does anyone have links to useful examples/articles/docs?
Sinatra docs are pretty great and easy to work with.
The examples in the couchrest repo seem to show a lot of use cases. https://github.com/couchrest/couchrest_model
The best way to understand code (and especially bleeding edge ruby) is to just read the code.
Updated, with link to tutorial: http://japhr.blogspot.com/2009/03/spike-sinatra-and-couchdb.html
You should probably look into the couch_potato library too, it just hits the sweet spot between the basic approach of couch rest and active record. Source and examples: https://github.com/langalex/couch_potato
I work at a small company and our production system uses a hand-rolled RESTful API, implemented in Java with JAXB. We now find that we're taking on customers who use Ruby on Rails, and I have to come up with a reference implementation to show customers how to use our API in Ruby. I'd love to be able to just tell them to use ActiveResource, but the XML required by our API uses (and absolutely requires) namespaces. Unfortunately, we've already got a number of other customers who've already integrated this API, so removing the usage of namespaces is out of the question. What's the best way to generate XML with namespaces in Ruby ?
"Best" obviously depends on your needs.
The fastest way to generate any XML in ruby is to use libxml-ruby - link to rdoc.
If your server gets any kind of load at all, this will be the way to go.
The easiest way to generate any XML in ruby is to use REXML as it's part of the standard library and therefore it "just works". If your XML generation is something that hardly ever gets used, it's probably easier to just go with rexml.
Both support XML namespaces - check the rdocs to find out how to set and get namespaces
I find myself in almost an identical situation as yours (RESTful API done with JAXB w/ namespaces).
I think the most promising project for working with XML in Ruby is HappyMapper. It is a kind of XML binding library (along the lines of an early JAXB-type implementation). It has been gaining a lot of traction recently, and a few of us have been working on providing good namespace support.
The project resides here:
http://happymapper.rubyforge.org/
with the source here:
http://github.com/jnunemaker/happymapper/tree/master
The project currently doesn't support creation of XML from Ruby Objects, and the original author has expressed no desire to provide that support, but I'll be committing some functionality for that in my fork:
http://github.com/jimmyz/happymapper/tree/master
Hope this helps.
--
Jimmy Zimmerman