Skip to content

Instantly share code, notes, and snippets.

View guinslym's full-sized avatar

Guinslym guinslym

View GitHub Profile
@guinslym
guinslym / example.rb
Created January 21, 2014 09:36
I'm praticing ActiveRecord::Association. I found this uml table in google (http://foss.unh.edu/resources/images/1/1f/BookRentalUML.png) and I wanted to put it in a /model/example.rb I was wondering how to do Heritage in Active Record? like for the Account table
#how Do I do heritage in Model
class Account < ActiveRecord::Base
has_many :bookRentalInvoice
end
class CheckAccount < ActiveRecord::Base
belongs_to :account
end
class CreditAccount < ActiveRecord::Base
@guinslym
guinslym / hex_is_null?
Last active January 3, 2016 23:49
verify if a hex value is null
#check to see if a hex String is null
"\u0080".unpack("h").each do |n|
a = n.to_i
if a.integer? && a.zero?
p n + " = this is an integer and it is empty"
else
p n + " not empty"
end
end
@guinslym
guinslym / association
Last active January 4, 2016 01:58
A Page has_many Section so that a Section belongs_to Pages. So if I want to retrieve all the "sections" of a Page I should write it like that "Page.sections" but I have an error.
2.0.0-p353 :042 > pages = Page.where(id: 48)
Page Load (0.4ms) SELECT `pages`.* FROM `pages` WHERE `pages`.`id` = 48
=> #<ActiveRecord::Relation [#<Page id: 48, name: "---\n- français\n", parent_id: 36, created_at: "2014-01-22 00:33:48", updated_at: "2014-01-22 00:33:48">]>
2.0.0-p353 :043 > section = Section.where(page_id: 48).count
(0.3ms) SELECT COUNT(*) FROM `sections` WHERE `sections`.`page_id` = 48
=> 3
2.0.0-p353 :044 > pages.sections
NoMethodError: undefined method `sections' for #<ActiveRecord::Relation::ActiveRecord_Relation_Page:0x00000004f53c60>
from /home/guinslym/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:121:in `method_missing'
from /home/guinslym/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:68:in `method_missing'
@guinslym
guinslym / gist:8575720
Created January 23, 2014 09:42
A 'page' may have many 'sections' I want to retrieve the 'sections.title' for each 'sections' that a page contains
2.0.0-p353 :041 > pages = Page.find(52).sections.count
Page Load (0.3ms) SELECT `pages`.* FROM `pages` WHERE `pages`.`id` = 52 LIMIT 1
(0.3ms) SELECT COUNT(*) FROM `sections` WHERE `sections`.`page_id` = 52
=> 2
2.0.0-p353 :042 > pages =Page.find(52).sections
Page Load (0.3ms) SELECT `pages`.* FROM `pages` WHERE `pages`.`id` = 52 LIMIT 1
Section Load (0.2ms) SELECT `sections`.* FROM `sections` WHERE `sections`.`page_id` = 52
=> #<ActiveRecord::Associations::CollectionProxy [#<Section id: 20, title: "La victoire est proche", body: "Guinsly t'e le meilleur Oat cake sweet roll browni...", page_id: 52, created_at: "2014-01-22 01:40:14", updated_at: "2014-01-22 01:40:14">, #<Section id: 36, title: "La victoire est proche", body: "Guinsly t'e le meilleur Oat cake sweet roll browni...", page_id: 52, created_at: "2014-01-22 01:40:15", updated_at: "2014-01-22 01:40:15">]>
2.0.0-p353 :044 > pages.each do |n|
2.0.0-p353 :045 > p.title
@guinslym
guinslym / exercice_class.rb
Last active January 4, 2016 07:48
IIn this function "def find_population_of_country(liste_pays, country_name)" Somehow it doesn't enter into the if statement
#!/usr/bin/env ruby
# => Class
class Country
attr_accessor :continent, :country, :capital, :surface, :population
def initialize(liste)
@continent = liste.slice(0,1).to_i
@country = liste.slice(1,35).strip
@capital = liste.slice(36,20).strip
@guinslym
guinslym / gist:8774515
Created February 2, 2014 20:35
heroku logs
guinslym@ubuntu:~/Documents/programming/project/impro2$ heroku logs
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/config.ru:in `<main>'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
2014-02-02T20:25:33.909001+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/commands/server.rb:48:in `app'
2014-02-02T20:25:33.909001+00:00 app[web
CKEDITOR.editorConfig = function( config )
{
config.width = 450;
config.forcePasteAsPlainText = true;
config.autoGrow_onStartup = true;
config.autoGrow_minHeight = 300;
config.fillEmptyBlocks = false;
config.autoParagraph = false;
config.toolbar_mini = [
['Format'],
@guinslym
guinslym / view_of_the_form_for_events_controller
Last active August 29, 2015 13:56
I'm getting an error of : undefined method `select_tag' for #<ActionView::Helpers::FormBuilder:0x0000000656e040> on the select_tag. :location without the "f." it's showing the SelectBox but it doesn't "post" the location string.
<div class="control-group">
<%= f.label :location, :class => 'control-label' %>
<div class="controls">
<%= f.select_tag :location, options_from_collection_for_select(Location.all, :parkname, :parkname) %>
</div>
</div>
@guinslym
guinslym / question.txt
Last active August 29, 2015 13:56
Question for tonight ruby meetup
Ruby:: understanding
----------lambda & Proc
Article.find_each(&:save)
---Is this a lambda, a proc? I don't understand it. I know what it does but what means the ":save" i didn't create a function to be yield
Rails:: Association
4.3.2.3 :class_name
http://guides.rubyonrails.org/association_basics.html
I don't understand this
"If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is Transaction, you'd set things up this way:"
@guinslym
guinslym / gist:8994519
Created February 14, 2014 01:58
Nokogiri::rails 3 nokogiri no such file or directory
Gemfile
...
gem 'nokogiri'
...
In controller