My main goal is to remove the backbone.js views/template and implement them to rails views. What is the best way/practices to do this? As there is lots of stuff going on the backbone.js views, is there any way that i can preserve the functionality and just convert them in rails views.
Helpful if you answer contains the steps.
Thanks.
I don't think is good idea to make any kind of dependency between your server layer and your client layer.
Starting from the point that the View concept in Backbone is nothing related to the View concept in Rails.
Related
I have a requirement in our project where we have around 20-25 similar kind of screens and the development needs to be done using MVC 4 Entity Framework.
So, I was looking for a solution on creating a single dynamic view.
So, Please suggest me and provide any useful links/sample applications if available.
Thanks in Advance,
Anand
You can use partial views for this purpose.
http://www.dotnet-tricks.com/Tutorial/mvc/2IKW160912-Partial-View-in-Asp.net-MVC3-Razor.html
I am currently developing a web project using Yii framework. I'm wondering where is a good place to put all the business logic, in the Controllers, or Models(models here as in mappings from database tables to actual objects)? Both doesn't seem right. I think I might need an extra "asset" layer in between controller and models, but I have no idea how to start. Any suggestions?
Generally the suggestion is to go about using Fat Models and Thin Controllers. So business logic in your model. It makes it far easier to make your code re-useable.
More info here:
http://www.yiiframework.com/doc/guide/1.1/en/basics.best-practices
If you've got a lot of custom logic, you could potentially have an "asset" layer of additional models that handled your DB models. Depends on your specific system though … I'm finding I do use CFormModel objects this way at times to map from a form with a bunch of different models to the models as needed.
As an exercise, I intend to replace all front-facing aspects of my Rails application with Backbone.js. Part of the plan includes redesigning everything right down to the CSS.
The issue I'm struggling with is in delegating responsibility for templates and views.
Is there any benefit to implementing the new front-end entirely in Backbone, hence only using Rails as an API?
How do I strike the right balance between Rails and Backbone when it comes to handling the HTML elements of the application?
Since it seems that nobody is going to post an answer to this I'll offer my two cents as just one point of view (I've written elsewhere about the issue of how to get rails and backbone.js to work well together: rails and backbone working together).
Most people in this situation will tend to drop the rails views altogether and migrate everything to backbone.js.
This is what I've done in a project that I'm working on right now.
This is the natural course of events, and particularly once you start getting used to all the complex interesting things you can do with backbone.js and structured javascript, it becomes difficult to turn back and implement standard stateless HTML pages.
As I mentioned in my other answer linked to above; however, there are costs to completely abandoning HTML views and the stateless layer. In my case, I intend to add back pure HTML pages for non-js-enabled browsers for GET requests only once the app has reached a certain level of functionality. We won't support POST or PUT requests unless the user has javascript enabled (or unless they want to go through the JSON API).
That's the balance I've struck: stateless HTML (no-JS) for accessing data, but JS required for posting/changing data. Your choice will vary depending on your use case and target user.
The other thing that I would mention is that if you have been working with rails HTML views on a project for some time, you might be unprepared for the initial overhead required to switch to backbone.js. This is not simply swapping HAML for ERB: you are migrating from a stateless front-end to a stateful one, and that is a potentially huge change (depending on the complexity of the app). I myself was a bit unprepared for the depth of that change, and had to do a lot of catching up before getting our app back on track after making the switch. And we made the switch very early, with minimal functionality already in-place.
Anyway just a few thoughts, hope they help.
I have an app that I'm building and would like to implement rails persistence to the backbone front end.
can someone point me to a simple repo or tutorial where i can learn about the configuration needed in rails to be able to persist data.
Thanks
I suggest to take a look at the backbone-rails gem.
It also provides a backbone:scaffold generator (I find that many rails generators can be used like "tutorial").
I am looking at a rails app and at the top of every controller there is a block of code that looks something like this
expose(:var) {Model.find params[:var_id]}
I understand what is inside the block just fine but...
I cannot find any documentation on what the expose function does where it comes from or anything I have tried searching the project and using the searchable rails docs.
I would love to know what it does, can someone please tell me or point me to the docs.
This is probably referencing the decent_exposure gem. You can learn more about it here: http://railscasts.com/episodes/259-decent-exposure
Source: https://github.com/voxdolo/decent_exposure
It's a method from the Decent Exposure gem. You can check out a screencast that Ryan Bates did on it over at Railscasts. It's a really great gem. I use it in my application. It cuts down on a lot of the redundancy in the controller layer.
expose is not a part of Rails, it comes from the decent_exposure gem.
It is not an answer to the question. I just want to make the Rails world a bit better and I hope that somebody will read this.
Please think twice before using expose. You should only use it if you 100% sure you are using it the right way and it really makes the code better. Read the documentation properly!
One of projects I worked on became unmaintainable because of tons of expose in controllers which replaced not only all #instance_variables passed to views, but also a lot of business logic and the most helper methods.
When you use expose it is not clear in which controller actions and in which views it is used. Unexperienced developers combine data and logic for multiple actions and multiple views in the same expose block.
That's a nightmare.
Believe me, expose really destroys projects if not used properly.