It works as a namespace, when the request is sent, your parameters are going to look like this ) ParamRoot: 'post' - This is a property used by the gem, its not a backbone property. Now go and open the post.js.coffee you will see that both a model and a collection were created now lets focus on the properties of those objects. rails g scaffold Post title:string content:string Now, let's create a rails scaffold and a backbone model for our post. The gem itself comes packed with some a fancy scaffold generator that almost does all the work for you, but, we'll put this aside and start everything from scratch, so, lets start with this generator that creates the basic structure for our backbone files: rails g backbone:install Now we have to include Backbone within our rails application, but, instead of downloading the file and put it into the assets folder manually, we are going to install the backbone-rails gem, so, now let's open our Gemfile and type the following and don't forget to bundle afterwards. This one handles the browser url box so we can trigger events when a route matches right after a hash tag (#).įirst let's create our rails project: rails new blog This one is simple, templates are like a rails views where you put all your layouts. This is where you bind all the Javascript events to the layout objects. If you think this is the place where you put all the layouts like in rails, well its not. This is like regular rails models, where all our data is stored and a large part of the logic.īackbone collections are simply an ordered set of models. If you are not familiar with coffescript, take a look at this post from one of my fellas.īefore we start let me explain some basic concepts about backbone and it's components: So, if you are not familiar with the framework and want to learn how to use backbone in your projects go ahead and check out this little tutorial where we'll be creating a basic blog. Recently, I have been involved in a couple of projects where we use a lot of Backbone.js, and even though I'm still learning, I can definitively help you out with the basics on how to code a basic CRUD with Backbone and Rails.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |