Hello here i have a haml index.
%h1 Requests
%table
%thead
%tr
%th Request Template
%th User
%th Sent At
%th Status
%tbody
- @requests.each do |request|
%tr
%td= link_to request.request_template_id, admin_request_template(requests.request_template_id)
%td= request.user_id
%td= request.request_sent_at
%td= request.status
If you see on the last line it says request.status. Right now it displays the status which is set to pending as default using an after_save in the Request Model.
I will like the user to click on the status and change it to Approved. How do i to do this? I have an array that can display the statuses. I also have a status column for the Requests table.
Please see my Request Model below.
class Request < ActiveRecord::Base
belongs_to :request_template
belongs_to :user
has_many :request_answers, autosave: true
validates :request_template, :user, presence: true
after_create :send_notification, :status_pending
STATUSES= %w[pending approved]
def send_notification
RequestMailer.delay.new_request_admin_notification(id)
request_notification_sent_date!
end
def request_notification_sent_date!
update_attribute :request_sent_at, Time.current
end
def pending!
update_attribute :status, "pending"
end
def approved!
update_attribute :status, "approved"
end
end
Aucun commentaire:
Enregistrer un commentaire