web
Ruby on Rails
Autor:
o web , .
o Ruby on Rails (RoR)
web
o Ruby je
o web
o RoR je open source
o RoR MVC
o Ruby
o DRY (dont repeat yourself)
(Andy Hunt)
(Dave Thomas), Ruby on Rails .
.
o "Convention over configuration"
.
o PhpMyAdmin MySQL
o PHP
o ySQL
o Apache Server
o Ruby
o Rails freamework
o JavaScript interpreter
o
o
o Web
:
Ruby :
www.rubyinstaller.org
Ruby on Rails
: www.railsinstall.org
o Windows :
/> ruby v
/> gem install rails --no-rdoc --no-ri
/> gem list --local rails
/> rails _4.0.0_ --version
/> rails v
o MySQL ( )
o PostgreSQL
o SQLite ( RoR )
o Oracle
o DB2
o Windows
:
> gem install mysql -d
o Command Line ( )
.
GIT (VC)
Windows CMD
o - Rails
.
Notepad ++
Sublime Text 2
o IDE (Integrated development environment)
,
.
o IDE- Rails :
RubyMine 5.4
Eclillipse +Aptana plugin
Aptana Studio 3
NetBeams
GIT editor
Code Editor
Test & Debugging App
Bundler
Rake
Smart coding assistance
Automatic deployment
via FTP or SFTP
Database Tools
o Ruby
o MVC
o .erb ( .html.erb)
o Ruby HTML kodu
o Ruby C-. : Smarttalk, Eiffel, Lisp Perl.
o 1993. Yukihiro Matsumoto . : I wanted a scripting language that was more powerful than Perl, and more object oriented than Python. Thats why I decided to design my own language.
o Ruby a , 2005. , Ruby on Rails.
o , Apple RoR Mac S , Leopard.
o .rb
o Ruby :
puts 'Hello, world!' #
puts 'blink ' * 4
var = 5 * (1+2) # e
@var1= 5 * (1+2) # instance
puts var
name = gets.chomp #
names = ['Ada', Nenad', Zoran'] #
puts names
puts names[1]
seasons =
{"winter"=>0,"summer"=>10,"spring"=>25,"autmn"=>12}
puts seasons["winter"] #Hash
def say_goodnight(name) #
result = 'Good night, ' + name
return result
end
puts say_goodnight(Nenad)
class Person # Person
def hello # hello puts 'hello' end end person1 = Person.new # person1.hello
o 1979.
. : , view ( Models, Views, Controllers).
o Controller . , View-a .
o View , .
o Model .
Browser Controller
Model Database
View
odluke
podaci prikaz
o web , , . , , , . , web .
o :
email encrupted_password
reset_password_token reset_password_sent_at remember_created at sign_in_cont carent_sign_in_at last_sign_in_at
carent_sign_in_ip last_sign_in_ip
admin
nivo_takmicenja
razred godina testovi resenje id_zadatka opis
naslov ime prezime email a_email poruka
razred oblast opis Zadatak
Testovi
Kontakt
Korisnici
Zadaci
korisnik Naslova
Strana
Fizika
o HTML5
o SaSS (CSS3)
o JavaScript
o jQuery
o GIT
o WBrick Server
o MySQL
o RoR
o Rails Get-plugin (Gem)
o Gem- web
:
Zurb-Faundation;
Devise - ;
Simple_Form - ;
Carrierwave - upload pdf, .jpg public
;
Will_paginate -
Role-model -
;
Turbolinks - RoR ;
jQuery-rails - JavaScript-
o C:\ > cd C:\WWW\RoR\PROJEKTI
o
> rails new FizikaPortal_Radni mysql d
o Windows
:
> cd FizikaPortal_Radni
o Windows WEBrick
:
> rails s
o :
o Localhost:3000 ( )
ctrl-c
o rake
:
> rake db:create
o mysql :
> mysql
o simple_form Gem :
> rails generate simple_form:install foundation
o zurb-foundation Gem :
> rails g foundation:install
o scaffold:
rails generate scaffold ime ime_promenjive1:tip_promenjive ime _promenjive2:tip_promenjive
o :
> rails generate scaffold test nivo_takmicenja:string razred:integer godina:date testovi:string resenje:string id_zadatka:string opis:string
o rake
(routes.rb):
>rake routes
o Views _form.html.erb
edit.html.rb
index.html.rb
new.html.rb
show.html.rb
o Models
test.rb
o Conrollers
test_controllers.rb
layout/aplication.html.erb
()
tests/
o Will paginate Gem-a
:
(app/controllers/test_controller.rb)
def index
@tests =Test.paginate(:page =>params[:page], :per_page =>
10).search(params[:search])
nd
(app/views/test/index.html.erb)
.# Tabela
(app/models/test.rb)
def index
@tests =Test.paginate(:page => params[:page], :per_page =>
10).search(params[:search])
end
(app/view/test/index.html.erb)
.....................
..........................................
def self.search(search)
if search
find(:all, :conditions => ['nivo_takmicenja
LIKE ? OR razred LIKE ? ', "%#{search}%",
"%#{search}%" ])
else
find(:all)
end
end
(app/models/test.rb)
(app/models/test.rb)
Unesi trazeni NIVO TAKMICENJA ili
RAZRED
'get' do %>
nil, :razred
=> nil %>
Carrierwave.
> gem install carrierwave
> rails generate uploader testovi create
o e :
(app/uploader/testovi_uploader.rb)
class TestoviUploader < CarrierWave::Uploader::Base
storage :file
def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
o app/views/_form.html.erb :
Unesi Test (.pdf)
o Users Devis :
> rails generate devise:install
o Devise views:
> rails generate devise:views
o User Devise:
> rails generate devise User
o FizikaPortal_Radni:
> rake db:migrate
o window- admin
users:
>rails generate migration AddUserIdToUsers admi
n:boolean
>rake db:migration
o :
o 1-
o 2- .
o before_action :authenticate_user! (app/controler/tests_controler.rb)
o (app/view/aplication.html.erb)
o
.............
..............
o (app/views/tests/new.html.erb)
o (app/views/tests/edit.html.erb)
(app/views/tests/_form.html.rb)
o (app/views/tests/show.html.rb)
..
Nivo takmicenja :
............
o Zurb-foundation Gem
o grid template-a zurb-foundation
framework-
Menu
O Fizici
Web
Fizika
Databa
se
URL: /users/inde
x
Route Rails
View (index.html.erb)
Model Active
Record
(user.rb)
Controller
(users_controller.rb)
1
2
3
4
5
8 6
7
/user index
User.all @user HTML
HTML
RoR
o Claud Host
o GITHUB+GIT
o Ruby on Rails open-source
,
.
o
Ruby framework
Rails-a
.
o
open-source
.
Recommended