code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
module UsersHelper
end
| Ruby |
module PostsHelper
end
| Ruby |
class User < ActiveRecord::Base
validates :first_name, :last_name, :email_address, :password, presence: true
end
| Ruby |
class PostsController < ApplicationController
def index
end
def new
end
end
| Ruby |
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
| Ruby |
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(params[:user].permit(:first_name, :last_name, :email_address, :password))
if @user.save
redirect_to users_path
... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflec... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters f... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# Be sure to restart your server when you modify this file.
Blog::Application.config.session_store :cookie_store, key: '_blog_session'
| Ruby |
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| Ruby |
Blog::Application.routes.draw do
resources :posts
resources :users
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'posts#index'
# Example of regula... | Ruby |
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Blog
class Application < Rails::Application
# Settings in config/environments/* take pr... | Ruby |
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Blog::Application.initialize!
| Ruby |
Blog::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers... | Ruby |
Blog::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web serv... | Ruby |
Blog::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suit... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
| Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Blog::Application.load_tasks
| Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | Ruby |
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.timestamps
end
end
end
| Ruby |
class AddSaltToUsers < ActiveRecord::Migration
def change
add_column :users, :salt, :string
end
end
| Ruby |
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to de... | Ruby |
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Us... | Ruby |
module WelcomeHelper
end
| Ruby |
module ApplicationHelper
end
| Ruby |
module SessionsHelper
def sign_in(user)
session[:user_id] = user.id
self.current_user = user
end
# setter method
def current_user=(user)
@current_user = user
end
# getter method
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def signed_in... | Ruby |
module UsersHelper
end
| Ruby |
class User < ActiveRecord::Base
#attr_accessor :password
email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]+)\z/i
validates :name, presence: true, length: {maximum: 50}
validates :email, presence: true, format: {with: email_regex}, uniqueness: {case_sensitive: false}
validates :password, presence:... | Ruby |
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
end
| Ruby |
class WelcomeController < ApplicationController
def index
end
end
| Ruby |
class UsersController < ApplicationController
def index
if !signed_in?
deny_access
end
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(params[:user].permit(:name, :email, :password, :password_confirmation))
... | Ruby |
class SessionsController < ApplicationController
def new
end
def create
user = User.authenticate(params[:session][:email], params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination"
render 'new'
else
sign_in... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflec... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters f... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# Be sure to restart your server when you modify this file.
Registration::Application.config.session_store :cookie_store, key: '_registration_session'
| Ruby |
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| Ruby |
Registration::Application.routes.draw do
get "welcome/index"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
root 'welcome#index';
resour... | Ruby |
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Registration
class Application < Rails::Application
# Settings in config/environments/*... | Ruby |
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Registration::Application.initialize!
| Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web... | Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the ... | Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the t... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
| Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Registration::Application.load_tasks
| Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | Ruby |
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.timestamps
end
end
end
| Ruby |
class AddSaltToUsers < ActiveRecord::Migration
def change
add_column :users, :salt, :string
end
end
| Ruby |
class CreateOwners < ActiveRecord::Migration
def change
create_table :owners do |t|
t.references :user, index: true
t.references :blog, index: true
t.timestamps
end
end
end
| Ruby |
class CreateBlogs < ActiveRecord::Migration
def change
create_table :blogs do |t|
t.string :name
t.string :description
t.timestamps
end
end
end
| Ruby |
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.references :blog, index: true
t.references :user, index: true
t.string :title
t.text :content
t.timestamps
end
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.references :post, index: true
t.references :user, index: true
t.text :content
t.timestamps
end
end
end
| Ruby |
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to de... | Ruby |
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Us... | Ruby |
module WelcomeHelper
end
| Ruby |
module ApplicationHelper
end
| Ruby |
module SessionsHelper
def sign_in(user)
session[:user_id] = user.id
self.current_user = user
end
# setter method
def current_user=(user)
@current_user = user
end
# getter method
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def signed_in... | Ruby |
module UsersHelper
end
| Ruby |
module PostsHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module BlogsHelper
end
| Ruby |
class Post < ActiveRecord::Base
belongs_to :blog
belongs_to :user
has_many :comments, dependent: :delete_all
validates :title, :content, presence: true
end
| Ruby |
class Owner < ActiveRecord::Base
belongs_to :user
belongs_to :blog
end
| Ruby |
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :user
validates :content, presence: true
end
| Ruby |
class User < ActiveRecord::Base
has_many :comments
has_many :posts
has_many :owners
has_many :blogs, through: :owners, dependent: :delete_all
#attr_accessor :password
email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]+)\z/i
validates :name, presence: true, length: {maximum: 50}
valida... | Ruby |
class Blog < ActiveRecord::Base
has_many :posts, dependent: :delete_all
has_many :owners
has_many :comments, through: :posts
has_many :users, through: :owners
validates :name, :description, presence: true
end
| Ruby |
class PostsController < ApplicationController
def create
@post = Post.new(params[:post].permit(:title, :content))
if @post.save
Blog.find(params[:blog_id]).posts.push(@post)
User.find(session[:user_id]).posts.push(@post)
end
redirect_to blog_path(params[:blog... | Ruby |
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
end
| Ruby |
class WelcomeController < ApplicationController
def index
if signed_in?
redirect_to blogs_path
end
end
end
| Ruby |
class CommentsController < ApplicationController
def create
@comment = Comment.new(params[:comment].permit(:content))
if @comment.save
User.find(session[:user_id]).comments.push(@comment)
Post.find(params[:post_id]).comments.push(@comment)
end
redirect_to blog... | Ruby |
class UsersController < ApplicationController
def index
if !signed_in?
deny_access
end
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(params[:user].permit(:name, :email, :password, :password_confirmation))
... | Ruby |
class BlogsController < ApplicationController
def index
if !signed_in?
deny_access
end
@blogs = Blog.all
end
def new
end
def show
@blog = Blog.find(params[:id])
@posts = @blog.posts.order("created_at desc")
end
def create
@blog =... | Ruby |
class SessionsController < ApplicationController
def new
end
def create
user = User.authenticate(params[:session][:email], params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination"
render 'new'
else
sign_in... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflec... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters f... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# Be sure to restart your server when you modify this file.
Registration::Application.config.session_store :cookie_store, key: '_registration_session'
| Ruby |
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| Ruby |
Registration::Application.routes.draw do
get "blogs/index"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
root 'welcome#index';
resource... | Ruby |
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Registration
class Application < Rails::Application
# Settings in config/environments/*... | Ruby |
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Registration::Application.initialize!
| Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web... | Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the ... | Ruby |
Registration::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the t... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
| Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Registration::Application.load_tasks
| Ruby |
class MathDojo
def initialize
@total = 0
end
def add(*arrays)
num = arrays.flatten
num.each {|x| @total += x}
return self
end
def subtract(*arrays)
num = arrays.flatten
num.each {|x| @total -= x}
return self
end
def display
return @total
end
end
puts MathDojo.new.add(2).add(2,5).subtract(3,2... | Ruby |
monster1 = {:name => "monster1", :health => 500}
monster2 = {:name => "monster2", :health => 500}
monsters = [monster1, monster2]
for i in 0..5
attack = rand(1..100)
attack2 = rand(1..100)
puts monster1[:name] + " attacks with #{attack} damage \n" + monster2[:name] + "'s health is now " + ((monster1[:health] -=... | Ruby |
a = {:first_name => "Michael", :last_name => "Choi"}
b = {:first_name => "John", :last_name => "Supsupin"}
c = {:first_name => "KB", :last_name => "Tonel"}
d = {:first_name => "Mikee", :last_name => "Buyco"}
e = {:first_name => "Diana", :last_name => "Manlulu"}
names = [a, b, c, d, e]
puts "You got " + names.count.to... | Ruby |
#!/usr/bin/ruby
# Foung Vang
# Ruby - Excercise 2
# just excercise
# String
x = "CodingDojo"
puts x.length # output: 10
puts x.class # output: String
puts x.upcase
puts x.downcase
puts x[2] # output: d
puts x.include?("dojo") # output: false because it's case sensitive
puts x.include?("dojo") # output: fa... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.