This file contains hidden or 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
Controller | |
class MongobrokersController < ApplicationController | |
skip_before_filter :verify_authenticity_token | |
#dont forget to change 56800 to 3600 | |
def air_hour | |
@air = Mongobroker.where(status: "up", node: "air", timestamp: (Time.now - 86400)..Time.now) | |
render :json => @air | |
end | |
def ema_hour |
This file contains hidden or 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
#This Script would ask for a person's first name, middle name, last name, and age separately, and would print, My first name is Ayodele, Adeniyi Abejide, I am 28 years old | |
puts "what is your first name?" | |
first_name = gets.chomp | |
puts "what is your middle name?" | |
middle_name = gets.chomp | |
puts "what is your last name?" | |
last_name = gets.chomp |
This file contains hidden or 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
Controller Method | |
def search | |
if params[:search_option] == "ink" | |
@ink = Ink.where("name LIKE ?", "%#{params[:name]}%") | |
elsif params[:search_option] == "printer" | |
@ink = Ink.where("brand_name LIKE ? AND serie_name LIKE ? AND printer_name LIKE ?", "%#{params[:brand]}%", "%#{params[:series]}%", "%#{params[:printer]}%") | |
end | |
@search = @ink | |
render :html => @search |
This file contains hidden or 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
class InksController < ApplicationController | |
before_filter :db_check | |
end |
This file contains hidden or 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
#The assumption here is a one-to-one mapping between controllers and models | |
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
protected | |
def db_check | |
model = self.class.to_s.gsub("Controller", '').singularize | |
Uploader.csv_loader(model) if eval(model).all.empty? | |
end | |
end |
This file contains hidden or 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
Model | |
uploader.rb | |
#The csv I am using were created from some code manipulation hence not well formatted, I am stripping off new lines and merging fields in some cases | |
class Uploader | |
def self.csv_loader(model) | |
File.open("#{Rails.root}/data/#{model}.csv", 'r').each do |row| | |
new_row = row.split(",") | |
case | |
when model == 'Brand' |
This file contains hidden or 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
Ruby code: | |
require 'csv' | |
class Phonecsvtoarray | |
attr_accessor :arr_path | |
def csv_to_array | |
arr = [] | |
CSV.foreach(@arr_path) do |row| | |
arr << row |
This file contains hidden or 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
User Model: | |
include Mongoid::Document | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
field :username | |
field :firstname |
This file contains hidden or 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
View | |
<%= form_for(:session, :url => sessions_path) do |f| %> | |
<%= f.text_field :password %> | |
<% end %> | |
Controller | |
class SessionsController < ApplicationController | |
def new | |
end |
This file contains hidden or 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
There are 10 CNUM | |
The CNUM value is 54973 | |
#<SOAP::RPC::Driver:#<SOAP::RPC::Proxy:http://172.18.100.13/KakawaCRM/soap.php>> | |
Wire dump: | |
opening connection to 172.18.100.13... | |
opened | |
= Request | |
<?xml version="1.0" encoding="utf-8" ?> |