This file contains 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 Human | |
attr_writer :name | |
def name | |
return @name | |
end | |
end | |
me = Human.new | |
me.name = 'samiron' | |
puts me.name |
This file contains 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
module AbstractBeverage | |
def cost | |
raise Exception, %Q|You should implement the cost for #{self.class}| | |
end | |
end | |
class DarkRoast | |
include AbstractBeverage | |
COST = 0.99 | |
def cost |
This file contains 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
require File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
require 'rails_autolink' #THIS IS THE PLACE YOU NEED TO ADD | |
if defined?(Bundler) | |
# If you precompile assets before deploying to production, use this line | |
Bundler.require(*Rails.groups(:assets => %w(development test))) | |
# If you want your assets lazily compiled in production, use this line | |
# Bundler.require(:default, :assets, Rails.env) |
This file contains 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 CommentsController < ApplicationController | |
# GET /comments | |
# GET /comments.json | |
def index | |
@comments = Comment.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @comments } | |
end |
This file contains 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
#config/routes.rb | |
map.route_a 'my_controller', :controller => "Users", :action => "a" | |
map.route_b 'my_controller/uid/:uid', :controller => "Users", :action => "b" | |
#Generated Links | |
route_a_url() ---> http://localhost:3000/my_controller | |
route_b_url(:uid => 10) ---> http://localhost:3000/my_controller/uid/10 | |
#Requesting to the above url redirects two different actions | |
#Output of rake routes |
This file contains 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
#Description: We want to show a region(parent) form | |
#while showing City information. | |
#If the form submitted with Region information, | |
# - New region will be created | |
# - City#region_id will have the new region id | |
def show | |
@city = City.find(params[:id]) |
This file contains 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
#FILE: app/controllers/cities_controller.rb | |
class CitiesController < ApplicationController | |
#When you do a ajax request the respond handler is ':js' | |
#So format.js will work. To render a response the new.js.erb | |
#file will be used. | |
def new | |
@city = City.new | |
respond_to do |format| |
This file contains 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
#FILE: models/user.rb |
This file contains 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 part of javascript needs to be included to make | |
a ajax call onchanging the selection value of dropdown. | |
Here, application.js is shown just for example. You should | |
load this based on your requirements. | |
*/ | |
//Use the id of your dropdown instead of "dropdown_id" | |
$(function($) { |
This file contains 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
sub sum{ doit('+', @_) } | |
sub fact{ mul(1..shift) } | |
sub mul{ doit('*', @_) } | |
sub doit | |
{ | |
my ($d, @nums) = @_; | |
return eval( join($d, @nums) ); | |
} |
OlderNewer