This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tenho a seguinte situação: | |
def update | |
ids = params["_json"].map { |hash| hash["id"] } # --> return [10, 20, 30, 40, 50] | |
positions = params["_json"].map { |hash| hash["position"] } # --> return [0, 1, 2, 3, 4] | |
query = MyQueryQuery.new | |
query.visible = true | |
query.active = true | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"public": [ | |
{ | |
"thumb": "/uploads/user/avatar/thumb_6fd0915dcee8eb1a04bb215f68ecfa5a.png", | |
"name": "Lucky Luciano", | |
"email": "lif****@xample.com" | |
} | |
], | |
"privates": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
string_collection = [ | |
"Web IconHTML & CSS100%", | |
"Command LineLearn the Command Line100%", | |
"Ruby IconRuby50%", | |
"Rails IconLearn Ruby on Rails100%", | |
"Git IconLearn Git100%", | |
"SassLearn Sass20%", | |
"JQuery IconjQuery1%", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_index(values, target) | |
values.each_with_index do |value, i| | |
return i if value == target | |
end | |
end | |
find_index([2, 4, 6, 8, 10, 12], 6) | |
# => 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<iframe width="700px" height="425px" src="http://online.fliphtml5.com/cgpf/jhut/#p=1" frameborder="0" allowfullscreen allowtransparency></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/forms/registration.rb | |
class Registration | |
include ActiveModel::Model | |
attr_accessor( | |
:company_name, | |
:email, | |
:first_name, | |
:last_name, | |
:terms_of_service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/registration_controller.rb | |
class RegistrationsController < ApplicationController | |
respond_to :html | |
def new | |
@registration = Registration.new | |
end | |
def create | |
@registration = Registration.new(registration_params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
resources :resgistration, only: [:new, :create] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.upto(100) do |i| | |
if i % 3 == 0 && i % 5 == 0 | |
puts "FizzBuzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
else | |
puts i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# para esse exemplo pressupõe-se que você tenha um recurso post com o campo >> content:string | |
#Primeiro criamos um model Tag | |
rails g model Tag name:string | |
# >> crie uma tabela CreatePostsTags com post_id e tag_id (para nosso relacionamento has_and_belongs_to_many) | |
rails g migration CreatePostsTags post:references tag:references | |
# >> modifique a migration CreatePostsTags add :id => false, já que não precisaremos de id nesta tabela | |
class CreatePostsTags < ActiveRecord::Migration[5.0] |
NewerOlder