Compare commits
4 commits
ae520e9076
...
d9faecf1bd
Author | SHA1 | Date | |
---|---|---|---|
|
d9faecf1bd | ||
|
c019c5ba20 | ||
|
0612d16e6b | ||
|
d4e35dbb5e |
5 changed files with 38 additions and 20 deletions
|
@ -2,9 +2,12 @@
|
|||
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :authenticate_user!
|
||||
|
||||
def require_user
|
||||
redirect_to root_path unless current_user
|
||||
end
|
||||
|
||||
def index
|
||||
redirect_to blazer_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,11 +42,22 @@ class ReadingsController < ActionController::API
|
|||
head :bad_request
|
||||
end
|
||||
|
||||
# Registra una Raspberry junto con su llave pública
|
||||
# Registra una Raspberry junto con su llave pública.
|
||||
#
|
||||
# Como el número de serie se agregó después, queremos migrar ad-hoc
|
||||
# las Raspberries que fueron registradas por su nombre y asociarles el
|
||||
# número de serie apenas empiecen a actualizarse los nodemecu.
|
||||
def raspberry
|
||||
@raspberry ||= Raspberry.find_or_create_by!(name: params[:controller_id]).tap do |r|
|
||||
r.public_keys.find_or_create_by(content: request.headers[:'X-Public-Key'])
|
||||
end
|
||||
@raspberry ||= begin
|
||||
r = Raspberry.find_by(serial_number: params[:serial_number])
|
||||
r ||= Raspberry.find_by(name: params[:controller_id])
|
||||
r.tap do |r|
|
||||
r.name = params[:controller_id]
|
||||
r.serial_number = params[:serial_number]
|
||||
r.public_keys.find_or_create_by(content: params[:public_key])
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Procesa la transacción
|
||||
|
|
|
@ -5,6 +5,6 @@ class Raspberry < ApplicationRecord
|
|||
has_many :arduinos
|
||||
has_many :public_keys
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
validates_presence_of :name, :serial_number
|
||||
validates_uniqueness_of :serial_number
|
||||
end
|
||||
|
|
18
db/migrate/20220314201955_add_serial_number_to_raspberry.rb
Normal file
18
db/migrate/20220314201955_add_serial_number_to_raspberry.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: tru
|
||||
|
||||
# Agrega el número de serie de cada RPi
|
||||
class AddSerialNumberToRaspberry < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :raspberries, :serial_number, :string
|
||||
|
||||
remove_index :raspberries, :name
|
||||
add_index :raspberries, :serial_number, unique: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :raspberries, :serial_number
|
||||
add_index :raspberries, :name, unique: true
|
||||
|
||||
remove_column :raspberries, :serial_number
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
--- rubygems.rb.orig
|
||||
+++ rubygems.rb
|
||||
@@ -764,10 +764,7 @@
|
||||
def self.platforms
|
||||
@platforms ||= []
|
||||
if @platforms.empty?
|
||||
- # XXX: Patched to avoid installing platform-specific gems with binaries
|
||||
- # linked against glibc.
|
||||
- @platforms = [Gem::Platform::RUBY]
|
||||
- #@platforms = [Gem::Platform::RUBY, Gem::Platform.local]
|
||||
+ @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
|
||||
end
|
||||
@platforms
|
||||
end
|
Loading…
Reference in a new issue