Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.23 KB | None | 0 0
  1. {_{_{_{ <| <| <| M - A - Y - T - S - C - H - I - D - Z - E - H |> |> |> }_}_}_}
  2.  
  3. # app/controllers/
  4. # -> application_controller.rb
  5. # app/views/
  6. # -> layouts/
  7. #    -> application.html.erb : Default template of the app
  8. #     <%= yield %>
  9.  
  10. # controller: - a + b
  11. # view: a + b = ?
  12.  
  13. # $ rails server
  14. # $ rails generate controller <name>
  15. # $ rails generate controller calculator
  16.  
  17.  
  18. # app/controllers/
  19. # -> calculator_controller.rb
  20.  
  21. class CalculatorController < ApplicationController
  22.   def index  # <-- action
  23.     # ...
  24.   end
  25. end
  26.  
  27. # app/views/
  28. # -> calculator/
  29. #    -> <action_name>.html.erb
  30.  
  31. # app/views/calculator/index.html.erb
  32. # <h1>GEI</h1>
  33.  
  34. # /upload -> action
  35. # home -> another action
  36.  
  37.  
  38. # config/routes.rb
  39.  
  40. Rails.application.routes.draw do
  41.   get 'calculator' => 'calculator#index'
  42. end
  43.  
  44. # -------------------------------------------------------
  45.  
  46. # /calculator?a=3&b=12
  47.  
  48. # app/controllers/calculator_controller.rb
  49.  
  50. class CalculatorController < ApplicationController
  51.   def index
  52.     a = params[:a].to_i
  53.     b = params[:b].to_i
  54.    
  55.     @result = a + b  # @ means instance variable (automatically accessible in the view)
  56.   end
  57. end
  58.  
  59. # app/views/calculator/index.html.erb
  60.  
  61. <h1>
  62.   <%= @result %>
  63. </h1>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement