Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC pattern for sinatra frame work

Tags:

ruby

sinatra

I want to start coding with 'Sinatra' framework but i cant find a 'MVC' pattern for this framework . Is an 'MVC-Sinatra' pattern or framework?

like image 766
my_little_fox Avatar asked Apr 28 '16 08:04

my_little_fox


2 Answers

You might want to check out Padrino

This is a framework built around Sinatra that provides a more "Rails like" feel to your project, but without as much hidden magic. It is a great example of what can be done with Sinatra.

Whilst this is great if you need to just get going, I would personally recommend that you use it as a learning tool to build your own apps using Sinatra in the way that makes the most sense to you. Write some tests / expectations, write some code, pass the tests - repeat :)

As for the ORM, you should also checkout Sequel which (imho) is very straight forward yet very flexible and powerful.

like image 130
sensadrome Avatar answered Oct 04 '22 12:10

sensadrome


Sinatra is a lightweight library, that aims to stay out of your way, leaving the door open for you to include or create what you need per project.

That said, you can create your own MVC on top of Sinatra rather easily, and incorporate ActiveRecord, DataMapper, Sequel, etc... for your Models. Here's a sample structure -

├── Gemfile
├── README.md
├── app
│   ├── controllers
│   │   └── application_controller.rb
│   ├── models
│   │   └── model.rb
│   └── views
│       └── index.erb
├── config
│   └── environment.rb
├── config.ru
├── public
│   └── stylesheets
└── spec
    ├── controllers
    ├── features
    ├── models
    └── spec_helper.rb

Gemfile - where all your gems go.

App Directory - folder for MVC directories - models, views, and controllers.

Models Directory - holds the logic behind your application.

Controllers Directory - where the application configurations, routes, and controller actions are implemented.

Views Directory - holds the code that will be displayed in the browser.

config.ru - the config.ru file is necessary when building Rack-based applications and using rackup/shotgun to start the application server (the ru stands for rackup).

Config Directory - w/ environment.rb fileto connect up all the files in your application to the appropriate gems and to each other.

Public Directory - holds your front-end assets - CSS / JS / Images, etc...

Spec Directory - contains any tests for your applications.

like image 20
typo Avatar answered Oct 04 '22 12:10

typo