Capybara uses selector css to find elements, we can do more than ".my-class" or "#my-id". XPath can be used to look for elements using different syntax, see above exemple.
| class MyModel < ActiveRecord::Base | |
| scope :custom_scope, -> { where.not(id: [1, 2, 3]) } # id not in (1, 2, 3) <=> id != 1 and id != 2 and id != 3 | |
| def self.class_method | |
| all.each { |x| puts x } | |
| end | |
| def to_s | |
| 'Hey' | |
| end |
| # toute donnée est un objet, y compris les types ; | |
| # toute fonction est une méthode ; | |
| # toute variable est une référence à un objet ; | |
| a = [1, 2, 3] | |
| b = a | |
| a << 4 |
| # params[:id] || params[:my_model_id] | |
| # routes.rb | |
| MyApp::Application.routes.draw do | |
| resources :my_models do | |
| collection do | |
| get :search # GET /my_models/search(.:format) | |
| end | |
| member do | |
| post :disable # POST /my_models/:id/disable(.:format) |
| # http://guides.rubyonrails.org/active_record_querying.html | |
| class Article < ActiveRecord::Base | |
| has_many :comments, -> { order('posted_at DESC') } | |
| end | |
| ##### REORDER ##### | |
| Article.find(10).comments.reorder(:name) | |
Redirect all your notifications ! (Receive text message in your computer).
Send text message from your computer.
| class CoolClass | |
| # This is the documentation | |
| # # return a string containing Something Cool or Something Coolest ! | |
| # arg1 = boolean # Default value to true | |
| # CoolClass.cool_method # return 'Something Cool' | |
| # CoolClass.cool_method(false) # return 'Something Coolest' | |
| def self.cool_method(arg1 = true) | |
| return public_method1 if arg1 | |
| private_method1 |
| # https://github.com/variadico/noti | |
| noti ls | |
| noti -t "Reply to Pedro" -m "Don't forget Pedro" sleep 1& | |
| export PUSHBULLET_ACCESS_TOKEN="Token" | |
| noti -p "Realy don't forget pedro" |
| class CustomObject | |
| attr_reader :a, :b | |
| def initialize(a, b) | |
| @a = a | |
| @b = b | |
| end | |
| def ==(other) | |
| (@a + other.a) == (@b + other.b) | |
| end |