Assuming you already have a Devise model named User and you want to add following Devise Security Extension to it:
- Password Expirable
- Password Archivable
- Session Limitable
| 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") |
| <%= form_with(model: team) do |form| %> | |
| <div> | |
| <%= form.label :name %> | |
| <%= form.text_field :name, class: "input" %> | |
| </div> | |
| <div> | |
| <%= f.select :user_id, {}, {placeholder: "Select user"}, {class: "w-full", data: { controller: "select", select_url_value: users_path }} %> | |
| </div> |
| import { Controller } from "stimulus" | |
| import moment from 'moment'; | |
| export default class extends Controller { | |
| static targets = [ "date_range" ] | |
| connect() { | |
| if(this.date_rangeTarget) { | |
| let selectedRange = false | |
| $(this.date_rangeTarget).daterangepicker({ | |
| showCustomRangeLabel: false, | |
| alwaysShowCalendars: true, |
| 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") |
I wanted to store arbitrary nested data structures in a jsonb column and be able to retrieve and work with that data seemlessly within a Rails application. There are several tutorials covering different aspects of this, but none felt complete to me.
For this example we'll be working with a User model that can define surveys. Each survey consists of n multiple choices questions, and each question can have between two and ten answer options.
In this case we use Postgresql's JSONB support to store the data, but you could also use other forms of serializing such as a text column and Rails' default YAML serializing. JSONB is chosen in this case because it leaves open the possiblity of querying the data with SQL. Also, apparently serializing to JSON is much faster.[1]
| module StrongParamsHelpers | |
| extend Grape::API::Helpers | |
| def permitted_params | |
| @permitted_params ||= declared(params, include_missing: false, include_parent_namespaces: false) | |
| end | |
| end |
| HTTP status code symbols for Rails | |
| Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
| Status Code Symbol | |
| 1xx Informational | |
| 100 :continue | |
| 101 :switching_protocols | |
| 102 :processing |
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb - load your rails into a pry sessionDebugger
#Scoped Invitation System for User Groups with Rails#
Starting out with the following models and associations:
####User
####Organization (User Group)