I have found some good stuff please check here
Translate
Friday, 18 September 2015
Wednesday, 19 August 2015
What is Self Joins ?
In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as between manager and subordinates. This situation can be modeled with self-joining associations:
class Employee < ActiveRecord::Base has_many :subordinates, class_name: "Employee", foreign_key: "manager_id" belongs_to :manager, class_name: "Employee"end |
In database management systems, a self-join is a query that joins a table to itself. This means that the same table is used twice in the join operation, but with different aliases to distinguish between the two copies.
Self-joins are typically used when we need to find relationships between rows within the same table. For example, consider a table that contains information about employees in a company. Each employee record may have a supervisor_id column, which contains the ID of that employee's supervisor. To find the name of an employee's supervisor, we can use a self-join to join the table to itself on the supervisor_id column.
Here is an example SQL query for a self-join:
SELECT e1.name AS employee_name, e2.name AS supervisor_name
FROM employees e1
JOIN employees e2 ON e1.supervisor_id = e2.id;
In this query, we are joining the employees table to itself, using the aliases e1 and e2 to distinguish between the two copies. We are selecting the name of each employee (using e1.name) and the name of their supervisor (using e2.name), where the supervisor_id column in the first copy of the table (e1) matches the id column in the second copy (e2)
Tuesday, 18 August 2015
How we can generate and run the application without the use of database in Ruby on rails?
-The program can be written in a normal file and executed by editing the file environment.rb and uncommenting the line where it is included.
-The program is as follows:
Path => rootpath conf/ environment.rb
# This is the comment that needs to be used as it tells that use this only with the rails.
config.frameworks -= [ :action_web_service, :action_mailer,:active_record ]
-The setting of the path needs to be done to show the correct fetching of the file and insertion of the records.
-The program is as follows:
Path => rootpath conf/ environment.rb
# This is the comment that needs to be used as it tells that use this only with the rails.
config.frameworks -= [ :action_web_service, :action_mailer,:active_record ]
-The setting of the path needs to be done to show the correct fetching of the file and insertion of the records.
What is the difference between Static and Dynamic Scaffolding
Dynamic Scaffolding is used to give the model name that is being used with the function like: scaffold: model_name. Whereas, Static Scaffolding requires manual entry in the command and it is given as:Script/generate scaffold Post title: string content:text category_id: integer
Dynamic Scaffolding automatically generates the entire content and user interface at runtime. Whereas, Static Scaffolding requires the insertion of the command to, generate the data with their fields.
Dynamic Scaffolding doesn’t require the database to be integrated as it gets created in runtime. Whereas, Static Scaffolding requires the database to, be migrated.
Dynamic Scaffolding allows the generation of new, edit and deletes methods for the use in application. Whereas, Static Scaffolding doesn’t allow any such generation to, take place.
What is Polymorphic Associations
A slightly more advanced twist on associations is the polymorphic association. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here's how this could be declared:
class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: trueendclass Employee < ActiveRecord::Base has_many :pictures, as: :imageableendclass Product < ActiveRecord::Base has_many :pictures, as: :imageableend |
How many type of associations available in rails
belongs_tohas_onehas_manyhas_many :throughhas_one :throughhas_and_belongs_to_many
what are the components define inside Model?
1) Validation
2) Associations
3) callback
Prepare same for controller
2) Associations
3) callback
Prepare same for controller
What does Session and Cookies represent in Ruby on Rails?
Cookies are stored key/value pairs (with other attributes such as
expiry,
specification for them is in the HTTP specification and these can
domain, path and ssl requirements) in the client's browser. The
technologies such as Javascript.
(generally) be read by backend languages such as Rails or frontend
Sessions are an unrestricted storage area for applications, generally
used
by the backend language only (due to encryption and hash protection with
server side secrets), although they may be stored in their entirety in a
requests have to come back to the same backend server.
client-side cookie for convenience to avoid "sticky sessions" where
Subscribe to:
Posts (Atom)