Rails notification

398 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
398
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rails notification

  1. 1. Architecture Rails: Controllers: Rails look to find controllers classes. A controllers handles a web request from user. Views: Holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser. Models: Holds the classes that model and wrap the data stored in our application's database. Helpers: Holds any helper classes used to assist the model, view, and controllers classes Methods: link_to → creates a hyperlink to an action example: <%= link_to "Hello", say_hello_path %> Marshaling Objects: Take an object and convert it into a stream of bytes that can be stored outside the app. rails generate migration add_columnname_to_tablename columnname:datatype example: rails generate migration add_password_to_users password:string Problem Solve Take-note Get URL parameter path = request.fullpath path_search = URI.parse(path) parse_url = CGI.parse(path_search.query) array_facility_choose = parse_url['search[facilities][]']#params['search']['facilities'] name_facility = Array.new # content all name of facility choose search[prefecture]=&search[departments][]=3&search[facilities][]=2 To create a model that references another, use the rails model generator: $ rails g model wheel car:references class Wheel < ActiveRecord::Base belongs_to :car end class CreateWheels < ActiveRecord::Migration
  2. 2. def self.up create_table :wheels do |t| t.references :car t.timestamps end end ActiveRecord Products.connection.execute('UPDATE `products` SET `price`=`free` WHERE 1') If the helpers not enough Rename column script/generate migration rename_my_column_by_hand Then edit the file it creates: class RenameMyColumnByHand < ActiveRecord::Migration def self.up rename_column :my_table, :old_name, :new_name end def self.down rename_column :my_table, :new_name, :old_name end end It executes SQL like: ALTER TABLE my_table CHANGE old_name new_name BIGINT; Change type of column class AddColumnToTable < ActiveRecord::Migration def change add_column :table, :column, :type end end Rails g migration changetypecolumn Add column rails generate migration add_password_to_users password:string rails generate migration add_columnname_to_tablename
  3. 3. columnname:datatype

×