image source
def show # get id from params # use id to get record from db # make record accessible using instance variable '@' # render template end
puts "My var here: #{my_var}"
<%= @my_variable.inspect %>
Started GET "/directors" for 130.126.255.106 at 2023-05-04 21:50:42 +0000 (0.2ms) SELECT sqlite_version(-) Processing by DirectorsController#index as HTML Rendering director_templates/index.html.erb within layouts/application Director Load (0.6ms) SELECT "directors".- FROM "directors" ORDER BY "directors"."created_at" DESC ↳ app/views/director_templates/index.html.erb:29 Rendered director_templates/index.html.erb within layouts/application (Duration: 7.6ms | Allocations: 5127) Completed 200 OK in 13ms (Views: 9.7ms | ActiveRecord: 1.5ms | Allocations: 7634)
rails c to enter a repl
rails c
debugger
c
n
def show my_id = params.fetch("id") debugger my_record = MyModel.where({ :id => my_id }).at(0) render({ :template => "my_views/show.html.erb" })
html.erb
<% debugger %>
rake grade
rails db:drop
rails db:migrate
rails console
describe "/movies/[ID]" do it "displays the title of the movie", :points => 1 do movie = Movie.new movie.title = "Flubber" movie.save visit "/movies/#{movie.id}" expect(page).to have_content(movie.title) end end
Try asking yourself (and each other) the following questions:
TODO: add an intermediate slide?