Skip to content

Instantly share code, notes, and snippets.

@sibinx7
Last active December 20, 2017 04:49
Show Gist options
  • Save sibinx7/8417146627ad57e105487aa20c758ef4 to your computer and use it in GitHub Desktop.
Save sibinx7/8417146627ad57e105487aa20c758ef4 to your computer and use it in GitHub Desktop.
Rails tutorial links

Rails Learning

Objectives

  • Learn authetication
  • Learn rake tasks
  • Learn Testing
  • Learn APIS
  • Learn popular gems
  • Learn about how to scale Ruby On Rails application
  • Realtime chatting
  • Frontend frameworks with Rails

Datatype

    string:      { name: "varchar", limit: 255 },
    text:        { name: "text", limit: 65535 },
    integer:     { name: "int", limit: 4 },
    float:       { name: "float" },
    decimal:     { name: "decimal" },
    datetime:    { name: "datetime" },
    timestamp:   { name: "timestamp" },
    time:        { name: "time" },
    date:        { name: "date" },
    binary:      { name: "blob", limit: 65535 },
    boolean:     { name: "tinyint", limit: 1 },
    json:        { name: "json" },

Routing

Inside routes namespace, controller outside namespace

resources :proposals, controller:  '/proposals' do

      end

Authetication

  • Device and Social authetication, Tutorial

Rails 5 : Action Cable

Rails migration, change column type

    unless column_exists? :projects, :published_at
      add_column :projects, :published_at, :datetime, default:Time.now,null:true
    else
      change_column :projects, :published_at, :datetime
    end
    
     # def down
     #   change_column :projects, :budget, 'integer USING CAST(budget AS integer)'
     # end

Multiple relation

Extra input on click

Rails Operators

Permit more columns in device, default prohibited columns

def serializable_hash(options = nil) 
    super(options).merge(encrypted_password: encrypted_password, reset_password_token: reset_password_token) # you can keep       adding attributes here that you wish to expose
end

Manual params creation

params = ActionController::Parameters.new(user: { name: 'Francesco', age: 22, role: 'admin' })
permitted = params.require(:user).permit(:name, :age)

Rails Fonts issue in production, Dirty solve

# config/environment/production.rb 
  config.assets.css_compressor = :sass
  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true
  config.assets.precompile += %w( .svg .eot .woff .woff2 .ttf )

Double assossiation

class Comment < ActiveRecord::Base
  belongs_to :student
  belongs_to :commenter, class_name: 'Student'
end

Form

<%= fields_for :permission, @person.permission do |permission_fields| %>
  Admin?  : <%= permission_fields.check_box :admin %>
<% end %>

Remote Form submission and JS

format.js   { render :js => "window.location.reload()"} // Reload Current url

Useful Gems

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment