I am trying to create my first custom controller actions for my final school project.
The value of the authorized_at attribute returns nil after trying to update it.
Errors are not displayed in the view; flash returns successfully. Can someone point me in the right direction please?
If I have not provided sufficient information, please let me know in the comments and I will add the necessary files.
registry_requests_controller.rb
class RegistryRequestsController < ApplicationController
def index
@registry_requests = RegistryRequest.all
end
def show
@registry_request = RegistryRequest.find(params[:id])
end
def approve
@approval = RegistryRequest.find(params[:id])
if @approval.save
@approval.update_attribute(:approved_at, true)
flash[:notice] = "The vehicle was approved for the Registry."
redirect_to request.referer
else
flash[:error] = "There was an error approving the vehicle. Please try again."
end
end
def deny
@registry_request.where(denied_at: true)
end
end
rail console
irb(main):003:0> RegistryRequest.first
RegistryRequest Load (0.2ms) SELECT "registry_requests".* FROM "registry_requests" ORDER BY "registry_requests"."id" ASC LIMIT 1
=> #<RegistryRequest id: 1, approved_at: nil, denied_at: nil, notes: nil, vehicle_id: 31, created_at: "2015-07-23 14:01:26", updated_at: "2015-07-23 14:01:26">
increase parameters
Parameters:
{"_method"=>"patch",
"authenticity_token"=>"F9RwL4WZbo8fXnjLqnQaG5gpVxW60JGSuqq5hPEeCJKGwPolJTNRIOmzyrX/HAsEmlwLQ9CXfS9PmNcK1OL9+A==",
"id"=>"1"}
registry_requests # show
<div><%= @registry_request.vehicle.make %></div>
<div><%= @registry_request.vehicle.model %></div>
<div><%= @registry_request.vehicle.description %></div>
<%= link_to "Approve", approve_registry_request_path, method: :patch %>
<%= link_to "Deny", deny_registry_request_path(request), method: :patch %>
Transfer registry requests
class CreateRegistryRequests < ActiveRecord::Migration
def change
create_table :registry_requests do |t|
t.datetime :approved_at
t.datetime :denied_at
t.text :notes
t.references :vehicle, index: true, foreign_key: true
t.timestamps null: false
end
end
end
What i tried
.save if @approval @appro.save update_attribute. update_attributes, : " (2 1)".
:
Started PATCH "/registry_requests/1/approve" for ::1 at 2015-07-27 10:47:15 -0400
Processing by RegistryRequestsController
Parameters: {"authenticity_token"=>"trCMgfHPT0LL5fOxVDmQyzRmpyFF4B/WeUHtzkvyHR0npAaLUWVw7T0IQc8BUYHUNhP7dy+n82uMc4NAbg7odw==", "id"=>"1"}
RegistryRequest Load (0.1ms) SELECT "registry_requests".* FROM "registry_requests" WHERE "registry_requests"."id" = ? LIMIT 1 [["id", 1]]
(0.0ms) begin transaction
(0.0ms) commit transaction
Redirected to http://localhost:3000/registry_requests/1
Completed 302 Found in 2ms (ActiveRecord: 0.2ms)
Started GET "/registry_requests/1" for ::1 at 2015-07-27 10:47:15 -0400
Processing by RegistryRequestsController
Parameters: {"id"=>"1"}
RegistryRequest Load (0.1ms) SELECT "registry_requests".* FROM "registry_requests" WHERE "registry_requests"."id" = ? LIMIT 1 [["id", 1]]
Vehicle Load (0.1ms) SELECT "vehicles".* FROM "vehicles" WHERE "vehicles"."id" = ? ORDER BY created_at DESC LIMIT 1 [["id", 31]]
Rendered registry_requests/show.html.erb within layouts/application (1.3ms)
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 6]]
Completed 200 OK in 72ms (Views: 71.2ms | ActiveRecord: 0.3ms)