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
#acho que da pra fazer assim, veja se funciona. | |
class RandomPasswords | |
def generate(size = 8) | |
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('1'..'9').to_a | |
(1..size).collect {|c| chars[ rand(chars.size) ]}.join | |
end | |
end | |
#nesse caso uma senha com 8 caracteres, se precisar ser maior ou menor mude o parâmetro ... dohhhh! |
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
MessagesController /action /create | |
def create | |
message = current_user.messages.build(params[:message]) | |
message.created_at = Time.now # HACK | |
message.save! | |
respond_with(@messages, :location => messages_url) | |
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
Message.joins(:department_targets).joins(:user).where("department_targets.department_id = ? OR users.department_id = ?", department_id, department_id) |
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 "json" | |
def temp() | |
number = Dir.glob('/sys/bus/w1/devices/*').count-1 | |
if number>0 | |
@temperatures = Array.new | |
Dir.glob('/sys/bus/w1/devices/*').each_with_index {|folder, index| | |
values = Hash.new | |
foldername = folder.gsub('/sys/bus/w1/devices/','') |
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
ENV['RAILS_ENV'] ||= 'test' | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'rails/test_help' | |
require "minitest/reporters" | |
Minitest::Reporters.use! | |
class ActiveSupport::TestCase | |
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. | |
fixtures :all |
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
# Defines the matching rules for Guard. | |
guard :minitest, spring: true, all_on_start: false do | |
watch(%r{^test/(.*)/?(.*)_test\.rb$}) | |
watch('test/test_helper.rb') { 'test' } | |
watch('config/routes.rb') { integration_tests } | |
watch(%r{^app/models/(.*?)\.rb$}) do |matches| | |
"test/models/#{matches[1]}_test.rb" | |
end | |
watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| | |
resource_tests(matches[1]) |
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] |
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
# 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
# app/controllers/registration_controller.rb | |
class RegistrationsController < ApplicationController | |
respond_to :html | |
def new | |
@registration = Registration.new | |
end | |
def create | |
@registration = Registration.new(registration_params) |
OlderNewer