Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this questionFor my next web application, I'm debating whether to use Rails 3.x or Sinatra.
I would like to use the server to provide user authentication, application-triggered emails, a fairly complex data model (behind ActiveRecord), and a JSON data interface with the web client. The client side will use static HTML, static CSS, Javascript/jQuery to render the JSON data into the views. The "policy" for rendering views will be driven by the Javascript code and some of the JSON data. I do not plan to use any dynamic view technologies such as ERB, HAML, or RJS.
Would I be better off with Sinatra or Rails 3.x?
Are t开发者_如何学JAVAhere any other questions I should ask before making that decision?
Your data model is fairly complex, so I imagine your application will have to handle a significant number of business rules and interaction possibilities.
Sinatra is meant for handling lightweight software architectures. If you choose Sinatra you'll probably encounter design and organization issues you'll have to handle by yourself. Rails implements the MVC pattern and can help you organize your code by offering a lot of useful mechanisms.
You still can build a "full-stack" web app with Sinatra but you'll have to do a lot by yourself especially if the amount of functionality you'll provide is high (or will grow). I think Rails fits naturally better in larger architectures.
PS : ActiveRecord is available both in Sinatra and Rails.
Sinatra would be a very good choice and I feel it would be better than rails mainly for one reason. This is linked with what another user wrote "You follow conventions and patterns which ensure your app will be easily maintainable and will scale well.
Some years ago we have developed a fairly large application in rails. All our developers had to do a complete rewrite because the rails core (read 37 signals) do not care to make their new version backward compatible. At every update the code would break.
So coding it in Rails will not ensure maintainability or scalability. Quite the opposite.
In fact scalability will be better on Sinatra as it is more lightweight and you would have anyway to use passenger for deployment. The Sinatra community is no-hype and extremely helpful. There are no prima donnas, big ego to the same degree of Rails. And this does matter because the Rails agenda might differ from yours and you might end up re-writing code very soon. There is a new book on Sinatra by O'Reilly that i think is worth a look as it is full of examples and ideas on what can be done and how.
I've got about the same task to do existing rails app that now needs a json interface for external devices (iPhone and Android apps). Highly suggest using sinatra-activerecord so you can just include all your models in your sinatra app. That way you don't have to rewrite your business logic.
Load your existing models in your sinatra app as follows: set :database, URI.encode( "#{db_settings['adapter']}://#{db_settings['username']}@#{db_settings['host']}/#{db_settings['database']}" ) require './data/models/user.rb'
And db_settings is loading it's settings from database.yml (same format as rails) use the yaml_db gem for that ;). This way your sinatra app can re-use all models and even the config files from the rails app.
Why would you ever use Rails for anything? Do you need template generators?
Writing an application with Sinatra or just pure Rack is just as easy as in Rails, and you get super speed for everything you do.
Sinatra apps can be organized in any way you want, and is much more flexible than Rails, making it the best choice no matter how large the application.
Making everything into micro-services and adding custom middleware feels much more natural with Sinatra and Rack.
People saying it's for smaller apps or architectures just haven't used it enough, I have no idea who started that myth.
You might want to take a look through the other lightweight Ruby frameworks before you decide - the post is a little old, but probably worth a scan.
精彩评论