Skip to content

Instantly share code, notes, and snippets.

View marcoroman89's full-sized avatar

Marco Roman marcoroman89

View GitHub Profile
@marcoroman89
marcoroman89 / users_controller
Created September 25, 2013 01:56
users_controller error
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(users_params)
if @user.save
flash[:notice] = "You have successfully registered, please log in!"
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :username
t.timestamps
end
end
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :post do |t|
t.string :title, :url
t.text :description
t.integer :user_id
t.timestamps
end
end
end
class User < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :user
end
@marcoroman89
marcoroman89 / gist:6143465
Created August 2, 2013 21:07
Cannot run rails server after ruby 2.0 and rails 4.0 installation
Marcos-MacBook-Pro:~ marcoroman$ rails -v
Rails 4.0.0
Marcos-MacBook-Pro:~ marcoroman$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
Marcos-MacBook-Pro:~ marcoroman$ cd blog
Marcos-MacBook-Pro:blog marcoroman$ ls
Gemfile Rakefile bin config.ru lib public tmp
README.rdoc app config db log test vendor
Marcos-MacBook-Pro:blog marcoroman$ rails server
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- bundler/setup (LoadError)
@marcoroman89
marcoroman89 / gist:6113713
Created July 30, 2013 15:00
Getters and Setters
class Card
attr_accessor :suit, :face_value
def initialize(s, fv)
@suit = s
@face_value = fv
end
def suit_output
puts "The #{face_value} of #{find_suit}"
@marcoroman89
marcoroman89 / gist:6113711
Created July 30, 2013 14:59
Getters and Setters
class Card
attr_accessor :suit, :face_value
def initialize(s, fv)
@suit = s
@face_value = fv
end
def suit_output
puts "The #{face_value} of #{find_suit}"
@marcoroman89
marcoroman89 / gist:6100302
Created July 28, 2013 21:23
The start of my procedural blackjack game!
# Interactive Ruby Based Blackjack Game
def calculate_total(cards) #[['H', '3'] ['K', '7']]
end
puts "Welcome to Ruby Blackjack"
suits = ['H', 'D', 'S', 'C']
cards = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
@marcoroman89
marcoroman89 / gist:6099031
Created July 28, 2013 15:48
Rails ActiveModel Error
ActiveModel::MassAssignmentSecurity::Error in Devise::RegistrationsController#create
Can't mass-assign protected attributes: email, password, password_confirmation
Rails.root: /Users/marcoroman/projects/treebook
Application Trace | Framework Trace | Full Trace
Request
Parameters:
get '/' do
if session[:player_name]
redirect '/welcome'
else
redirect '/game'
end
end
get '/welcome' do
erb :welcome