Wednesday, December 16, 2009

Partial Highlights Brown Hair Images

Rails: project structure and scaffolding

In a previous post I described how to install, create and run Rails. In this article I will discuss some more looks like a standard directory with the application together with the purpose of each folder.
Framework Ruby on Rails fairly accurately determine how you want your each web application. At first glance, some rigid rules may seem a limitation, however, introduced in Rails conventions eventually enable a very quick orientation of each project in Rails, even if you have not worked in a project over which we assume custody. The structure, file naming, and even the names of specific keys in the database schema allows that we can skip the step of defining and setting up at a very accelerated, not only writing, but above all, to work on existing code.

When you open an application, we see more or less a set of directories


app config db


doc lib log


public Rakefile README

script

test tmp vendor



Product app is the most important directory for the project - are placed in the class definitions that make up the implemented in Rails MVC pattern . We find where all controllers, models and views. This directory is divided into sub-folders: controllers - which are in separate files to controllers, models - in which the files are stored definition of the different models. The other folders contain files views and views helpers - the folder that contains the auxiliary modules available during the rendering of the view.

config directory contains the files defining application configuration parameters and above all the settings to access the database config \\ database.yml . In addition to the standard Rails files Ruby (. rb) is often used YAML format (files with the extension. yml). These files are parsed by the Rails environment, and they are read from the configuration parameters.

catalog db contains files associated with the database used - primarily located in the files used to create (and play), so the database schema. migrations. Migrations in Rails creates introduced a special meta-language that allows the manipulation scheme, independently of your database engine - with the migration and they provide mechanisms for abstraction is not to be relevant (except possibly aspect of the extreme performance and data security), or use MS SQL, Postgres or SQLite database files - a diagram will be created in a similar way and obtain the same functionality.

Another important site is the directory log . The standard Rails application can be run in one of three modes: development, test and production. These modes are different configuration settings - including options, which for example determine what is to be recorded in the logs. Each of these modes has its own log file: development.log, test.log, production.log. Preview the files you podpatrzeć eg code models generated by SQL, requests sent by customers of our application with parameters, and the share taken by the controller when generating the response for the browser.

Some applications, which typically consist of files. Css, javascript libraries and static objects flash and pictures used in any web application is not generated by the Rails application. All these files should be stored in the directory public. With these files can be directly used by embedding them in the form of an appeal with links placed in the HTML view.

The directory script includes scripts for managing the application. Most important is the script \\ server - allows you to run the server application. A very important feature is the option-e, which determines the Rails environment starts. If you omit this parameter by default, starts up the development environment (development). Moreover, it is very important script file script \\ generate - it allows the use of the installed along with the Rails code generators - they allow the creation of frameworks of individual application components such as models, controllers, together with views and migration.

The directory test generated code is placed in automated tests. More about the directory structure I posted in the following parts of this tutorial. Now just add that in addition to the tests shall also contains files with test data that are loaded at startup so each test. fixtures.

In the main application directory is also your Rakefile. Rakefile is equivalent to the makefile used to build applications for tools for C / C + +. Role in Rails takes to make the rake of the fact that this is not to compile, and the majority of cases to perform operations such as the database (load test data from the fixtures, the execution of the migration pattern), deletes temporary files, etc. For a complete list of sessions defined operations, we can list all by adding the parameter - tasks like the following


rake - tasks


After discussing the directory structure is time to generate a functional example.
In this series I will try to prepare a simple application for managing contacts. Applications that will create incremental value in a few episodes to show how to apply TDD methodology and BDD.

Assume that our application will initially be allowed to collect contacts. Contact
is an object which will keep the name. To generate such a simple application in Rails, in principle, no need to program. Each project has a Rails generator to generate such a framework, which nevertheless has the functionality to allow you to add, delete and edit a resource, a full CRUD -a. Total generate one command:

ruby \u200b\u200bscript \\ generate scaffold name: string surname: string

The only thing you should do is modify the database schema:

rake db: migrate

and possibly restart the server (close the console and start again)

ruby \u200b\u200bscript \\ server


These commands operate the configuration and database development environment - in other environments, you must set the environment variable RAILS_ENV respectively, testing or production:

rake db: migrate RAILS_ENV = test
ruby \u200b\u200bscript \\ server-e test


Now browser by going to http : / / localhost: 3000/contacts - We can add new contacts and edit or browse existing ones.

In the next post I will try to write the first tests of this application and to modify slightly the initial functionality.

Tuesday, December 15, 2009

Play Virtual Emo World

Rails Quick Start

As a friend recently I presented the possibility framework Ruby On Rails also crossed my mind to somehow prove their achievements - during the preparation of presentation tidied up a bit of knowledge.
know, I know ... There are thousands of these tutorials, but I will try to explain the process of creating a web application with particular emphasis on the testing process and use Rails built-in capabilities to automate the test process.

I also have a plan to attempt in future posts to compare Rails with Django or PHP ZendFramework . We'll see what will come out so far:

Let's get started!

Firstly, if you do not have to deal with Ruby on Rails is as the name suggests, this framework is based on Ruby. Like the PHP language is dynamic - that is, we write scripts that could be immediately launched by the interpreter. Interpreters for interpreted
Ruby is available in several versions - best-known and stable for the moment is version 1.8.6 (it will refer to throughout the specification). There are also versions 1.8.7 and 1.9.1 (which in future will eventually replace the line 1.8.6). Maybe less known, but worth mentioning feature is the ability to use JRuby . In this case, the interpreter is run by a Java environment - which is interesting JRuby can be significantly faster than implementations written in pure C. This may be due to the fact that optimizes the Java virtual machine executes code during runtime. In addition, the Sun guys have great experience in matters takich jak zarządzanie pamięcią ( garbage collector ). Siła Javy może ujawnić się szczególnie w przypadku kodu wielowątkowego - istniejące w Ruby implementacja wątków jest typu Green Thread - JRuby zastępuje ją wsparciem wątków jakie oferuje Java.
Przed wejściem w świat Ruby on Rails warto zapoznać się choćby pobieżnie ze składnią Ruby - w tym celu warto zajrzeć na stronę www.ruby-lang.org . Znajdują się tam (także po polsku) informacje na temat składni oraz wprowadzenia dla osób potrafiących już programować w innych językach. Jeśli chcemy czuć comfortable reading Ruby code, we should at least be familiar with such structures characteristic of this language as
- blocks
- dopants (mixings)

Installation Environment (Windows):

standard language interpreter can be installed in two ways - by downloading the package in an archive zip file or selecting one-click-installer version available for ruby-1.8.6. All relevant instructions are provided in the documentation available which I will not duplicate. However, for its part, I can only suggest making sure that we can run after you install the interactive interpreter Language (IRB), which means that you need to check whether the user's path has been appended to the bin folder of the folder where you installed Ruby (default is C: \\ ruby \u200b\u200b\\ bin on Windows).
In fact, after using the option one-click-installer we are ready to start playing with Rails.

Ruby libraries are distributed in the form of so-called. Games. If someone had been in contact with the type of distributions Debian / Ubuntu installer or the PEAR library for PHP - gem package manager is the equivalent of those systems.
exercising command gem install rails easily find on your disk All you need to start playing components.

After installation, we are now ready to generate the application. Installing Ruby on Rails scripts directory completed a series of commands for application management Rails. To generate the skeleton of the project, use the command:

rails crud_example

script will copy the directory of the project all the necessary files and creates a skeleton application.
If we enter into that directory: cd

crud_example

we can run the generated application (in fact the skeleton) by:

script \\ server

If we now introduce you open the browser and the address http://localhost:3000/ you should see the home page of our application.

And that's when it comes to running. Next time I will setup access to the database and will create a simple working prototype.

Monday, December 14, 2009

Uses Of Aswini Hair Oil

Everything is an object

recently during a presentation, when I start the console Ruby somewhat surprised - after defining any function in the interpreter such as this:

irb (main): 001:0> def function
irb (main): 002:1 > puts "Hello World"
irb (main): 003:1> end
=> Nil irb
(main): 004:0>

unless each facility has been able to call this function on his behalf. Was surprised to see that it works for example, such a thing:

irb (main): 004:0> "Hello World 5.funkcja

=> nil

also

irb (main): 005:0> "a piece of text." Hello World function

=> nil

Rummaging little documentation and googlach eventually all became clear. And so one after another: When you open the interpreter in a kind of object that created the interpreter. You can check this by typing the command line:

irb (main): 006:0> self
=> main
irb (main): 007:0>

Moreover, the very inform the interpreter's prompt 'irb ( main): 007:0> '- but I do not think I would have fallen that it is in main building. Sam
main object is of type Object:

irb (main): 007:0> self.class
=> Object

Now, if you will list all the methods defined for the main building where you will find our function, inter alia:

irb (main): 008:0> self.methods
=> ["inspect", "pushws", "cwws", "clone", "cb", "help",
...
"irb_print_working_binding", "===", "workspaces", "instance_variable_set", "irb_pop_binding",
"kind_of?", "extend", "irb_chws", "to_s", "irb_pushws", "irb_require", "irb_pwws
", "hash", "class", "irb_cb", "include", "irb_context", "tainted?", "=~", "priva
te_methods", "irb_pop_workspace", "irb_cwb", "irb_jobs", "nil?", "funkcja" , "unt
aint", "irb_bindings", "exit", "irb_current_working_workspace", "irb_popb", "irb
_cws", "is_a?", "Fg"]

5 (Fixnum) and "string" (String) Object inherit what can you look like this:

irb (main): 009:0> 5.is_a? Object
=> true
irb (main): 010:0> "string". Is_a? Object
=> true

therefore, such a proposal: the class object by modifying the object and placing it in any way - it becomes instantly available to all child classes of objects. Interesting ...