from http://www.ruby-doc.org/docs/ProgrammingRuby/language.html#table_18.4
Y| Method | Operator | Description |
|---|---|---|
| http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query | |
| http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails | |
| #payload: [{"kind"=>"person"}] | |
| Segment.where("payload @> ?", [{kind: "person"}].to_json) | |
| #data: {"interest"=>["music", "movies", "programming"]} | |
| Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json) | |
| Segment.where("data #>> '{interest, 1}' = 'movies' ") | |
| Segment.where("jsonb_array_length(data->'interest') > 1") |
| class ParamsSlicer | |
| def initialize(params, *whitelist) | |
| @params = params | |
| @nested_whitelist = whitelist.extract_options! | |
| @whitelist = whitelist | |
| end | |
| def call | |
| params.slice(*whitelist).tap do |result| | |
| nested_whitelist.each do |k, v| |
from http://www.ruby-doc.org/docs/ProgrammingRuby/language.html#table_18.4
Y| Method | Operator | Description |
|---|---|---|
| # activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb | |
| # Maps logical Rails types to MySQL-specific data types. | |
| def type_to_sql(type, limit = nil, precision = nil, scale = nil) | |
| return super unless type.to_s == 'integer' | |
| case limit | |
| when 1; 'tinyint' | |
| when 2; 'smallint' | |
| when 3; 'mediumint' | |
| when nil, 4, 11; 'int(11)' # compatibility with MySQL default |
http://guides.rubyonrails.org/migrations.html
| # updated from the original @ http://cheat.errtheblog.com/s/rspec_shoulda | |
| # just a subset -- models -- is included here. I'll update this, and create cheat sheets for others, as I go along. | |
| # I marked the ones I added with NEW and also added the links to the corresponding code, as I think it's useful. | |
| # Any comments/corrections are welcome! | |
| # ================= Data and Associations ======================= | |
| # https://github.com/thoughtbot/shoulda-matchers/tree/master/lib/shoulda/matchers/active_record | |
| it { should_not have_db_column(:admin).of_type(:boolean) } |
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |