I want to customize rails scaffolding. For that I want to set up a custom template engine.
Can anyone guide me to set a custom template-engine.
You don't need a custom template engine to customize rails scaffolding. Depending on what you're trying to do, you can customize your rails generators or use a tool such as rails-composer / rails_apps_composer.
If you're looking to switch the default template engine, for rails 3, you can use --template-engine flag. There are also options such as Tilt that provide a layer of abstraction so that it's easier to switch between the leading options.
Related
We have website which built in yii 1.1 version, now we would like to convert it to version 2. But we already have a lots of functionality and we do not have much time to do everything by scratch in yii 2. please do suggest.
I don't think there is a fast way of converting or migrating from Yii 1.1 to Yii2. They are similar in some ways but different enough.
I would recommend you first read most of The Definitive Guide to Yii 2.0, which includes Upgrading from Version 1.1.
In my opinion the best you can do is try to replicate the same modules and their functionality one at a time, trying to reuse as much code as you can from the 1.1 version. A few things that i think would be important are:
Create the new Yii2 models using Gii and adapt methods from your Yii 1.1 models. Edit and add validation rules as needed. There are many rules that might not have been available in Yii 1.1, however it can also be true the other way around.
Generate Yii2 modules with Gii. Just need these to create a better project structure. If you didn't use modules on Yii 1.1 i would recommend doing so for Yii2.
Generate Yii2 CRUDs with Gii inside the corresponding modules. This will help generate the controller, actions, views and search model needed for basic CRUD functionality. After that, you will need to edit the views and controller to fit your needs, which you can use your 1.1 code for reference.
Install needed extensions and widgets using composer. Many extensions from Yii 1.1 have updated versions for Yii2, but for those that do not you will have to find substitutes, which shouldn't be too difficult, although you will most likely have to read the documentation for both familiar and new extensions.
In the end you will need to spend time to have a Yii2 version of your website, there is no easy and fast way to jump
You don't need to convert your application completely you can use both at same time please have a look to
http://www.yiiframework.com/doc-2.0/guide-tutorial-yii-integration.html
I am new to Yii framework, and just came across extensions provided by Yii. But I am confused whether we can modify the extension which are provided by Yii.
For example I am using Yii-user module, Now if I want to change the registration form provided by this module, So can I directly change it(by changing the files) ?
If - Yes: Will there be any problem while upgrading Yii version ?
If - No: How can be change it(May be from our custom file) ?
Yii-user module is provided by the community not an official yii extension, yes you can modified by replace it with another view file, if you mean a class the best way to modifie it is by extend it and override the methods you want to change.
Hope it helps
Yii is designed to build custom solutions, you should feel free to modify anything that is part of the generated 'site' including extensions and everything in the protected folder. However, conforming to the psyche and standards of coding used in Yii is certainly a good practice to benefit fully from the framework and you can only get into a habit of doing that after developing and re-developing with Yii over a period of time.
Upgrading Yii version updates files in the framework directory only so its safe to make changes in your site part.
You cannot upgrade that individual extension if you modify them directly(as now you have your own custom version). extending an extension as suggested by Cherif is a good option if you want to keep upgrade-ability for the extensions (protected/extensions).
I am developing a web-based simulation where I want the front-end to be "animated" in real-time--it will be a mapping application, and I want to have little icons (representing the components of my simulation) moving all over the map as the simulation runs. I am developing the back-end in Rails, but I am wondering what are good packages to use for the front-end / animation part? I used Graphviz to generate the base map (a directed graph), but it doesn't seem well suited for live animations.
Something like Hans Rosling's Gapminder (if it's even possible to do in real-time). Or should I be doing something similar and "recording" the data then playing it back? What packages should I consider in that case?
Gapminder
Currently using Rails 3.0, Ruby 1.9.2, Graphviz 2.28.
Here are 2 javascript libraries that may help. You could use ajax calls to your rails backend to populate their data. I'm unsure if D3 has mapping capability, but I believe Raphael does. As far as real-time, you'll have to check out their documenation. In Rails 4, I believe the streaming capability may benefit you as well, but I've not investigated.
Raphael
D3
Assume I have a running ruby on rails app.
I’m creating classes (db-models) defined by a description provided at runtime.
Right now, I’m using the rails app (via browser) to trigger the code generation — and therefore the app “knows” about its new classes.
But, is it possible to inject code from scripts executed inside the rails app directory?
Like…
$ [path/to/app] rails s
$ [path/to/app] script/apply_schema
Since RoR supports many helpers for both generating tables, columns etc. I do not see why you want to do this using script injection. this would not only be a very weird way of inputting and rendering data but it would also create quite a security risk.
Then comes my second question (in runtime) how would you define authentication? since you are trying to inject code?
I would advise using the SQL helpers to create/update/destroy attributes. this is based on a much used and effective architecture. also using relations makes you able to build quite alot while still remaining in the "safe" environment RoR offers.
If you want to try a framework wich offers data injection on runtime try Meteor
I'd like to see an example of an application generator template for Rails 3. Any suggestions?
I'm interested in an example of a template that is used to generate a new Rails application. Ryan Bates has a screencast (#148 App Templates in Rails 2.3) that describes how to create an application generator template for Rails 2.3 but I'd like to see how something similar is implemented in Rails 3. I've seen several tutorials on using the Rails 3 generators but I haven't found anything that shows how to create an application generator template.
I presume all of the capabilities of Thor and Rails::Generators::Actions are available but I'd like to see how to use them in an application generator template.
It seems terminology is confusing here. "View Template Engines" (such as Haml) are one thing; "Rails Generators" (such as used for "rails generate helper") are another thing; and "Application Generator Templates" (used for "rails new app_name -m some/path/to/template") are quite another thing.
Dug around in the Rails source and answered this question myself :-)
Here's an example of an application generator template for Rails 3:
http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
Usage:
rails new app_name -m http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
In customizing this template, you can use any methods provided by Thor::Actions
http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html
and Rails::Generators::Actions
http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb