Skip to content

Instantly share code, notes, and snippets.

View guinslym's full-sized avatar

Guinslym guinslym

View GitHub Profile
@guinslym
guinslym / gist:7994888
Last active December 31, 2015 13:48
Ruby Error with in the Regex
require 'digest' #for password hasing
class User < ActiveRecord::Base
#It tells Ruby to create reader and writer methods for password. Because the password
#column doesn’t exist in your table anymore, a password method isn’t created automatically
#by Active Record. Still, you need a way to set the password before it’s encrypted, so you make
#your own attribute to use. This works like any model attribute, except that it isn’t persisted to
#the database when the model is saved.
attr_accessor :password
@guinslym
guinslym / gist:8050615
Created December 20, 2013 05:08
This is how my altered DeviseCreate migration looks like
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Rememberable
t.datetime :remember_created_at
@guinslym
guinslym / gist:8050722
Created December 20, 2013 05:23
I fixed my problem. But I was wondering if it's possible to create a table like this (see:: second gist - original).. Cause there is an add_index: email but there is no t.string :email, in the Do Block
#This is my file altered... the one that works for me
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Rememberable
t.datetime :remember_created_at
@guinslym
guinslym / gist:8110087
Created December 24, 2013 07:52
Comments_controller. Books (Beginning Rails 4 (chapter 9)
class CommentsController < ApplicationController
before_filter :load_article, :except => :destroy
before_filter :authenticate, :only => :destroy
def create
@comment = @article.comments.new(comment_params)
if @comment.save
redirect_to @article, :notice => 'Thanks for your comment'
else
@guinslym
guinslym / new.js.erb
Created December 24, 2013 18:02
Wrong javascript output. I'm trying to load a form using Javascript. So that when I user click on "new Comment" it will append the 'comment form' but when I clicked on the link it renders $("<form accept-charset=\"UTF-8\" action=\"/articles/3/comments\"...
$("<%= escape_javascript render(:file => 'comments/new.html.erb') %>").insertAfter('#comments');
$('#new_comment_link').hide();
@guinslym
guinslym / want_to_accomplished
Last active January 1, 2016 10:19
I want to add inside of link_to an Icon-tag I have some difficulties with adding it.
<a href="path...">
<i class="icon-home" icon-large="2x"></i>
Home
</a>
@guinslym
guinslym / gist:8193851
Last active January 1, 2016 19:59
wrong number of arguments (3 for 2) for when ".csv" then Roo::Csv.new(file.path, nil, :ignore)
class Product < ActiveRecord::Base
require 'roo'
validates_presence_of :price
def self.to_csv(options = {})
CSV.generate(options) do |csv|
csv << column_names
all.each do |product|
csv << product.attributes.values_at(*column_names)
end
@guinslym
guinslym / gist:8217189
Created January 2, 2014 10:03
I ran this Hash in my console << ruby example.rb but my students.count doesn't appear?
#!/bin/ruby
#all those informations are fictive
students = {:VILC22579307 => "VILLENEUVE-ASSE, CINDY",
:NDIJ19129106 => "NDIAYE YEND, JEAN-LOUIS RUDY",
:JEAJ03108909 => "JEAN-BAPTISTE, JOSEPH-RAYMOND MARC",
:ELME29089109 => "EL MOUTARAJJI EL ALA, ELIAS",
:TRED01039200 => "TREMBLAY, DENIS MARC-ANDRE PIERRE",
:AUCM28579305 => "AUCLAIR-JULIEN, MARIE-ISABELLE"}
students.count
@guinslym
guinslym / gist:8224915
Last active January 2, 2016 00:39
Having a problem with case statement example_case.rb:95: syntax error, unexpected end-of-input, expecting '}'
puts "afficher le mois de naissance explicitement"
students.each { |k, value|
mon_mois = le_mois k.slice(6,2).to_i
puts "etudiant #{k} est ne en #{mon_mois} "
}
#return a month name
def le_mois number
number = number > 50 ? number-50 : number
case number
@guinslym
guinslym / _gallery.hml.erb
Last active January 2, 2016 01:49
I want to implement lightbox2 => http://lokeshdhakar.com/projects/lightbox2/ I have downloaded the files and add it to vendor/assets/javascript vendor/assets/stylesheets and vendor/assets/img ==> (that's a folder that comes with lightbox)