I am working on an application with has_many through association. in employee.rb
class Employee < ActiveRecord::Base
has_many :inventories, through: :employee_inventories
end
in inventory.rb
class Inventory < ActiveRecord::Base
has_many :employees, through: :employee_inventories
end
in employee_inventories.rb
class EmployeeInventory < ActiveRecord::Base
belongs_to :employee
belongs_to :inventory
end
Everything is fine with this association. But when I implement if-elsif condition with accessing status column from employee_inventory. Like that
<% if (inventory.is_available == false && current_employee[:role] == 'INVENTORY') %>
<% if(inventory.employee_inventories.collect{|e| e.status == 'REQUESTED'}) %>
<%= link_to 'Allot', inventory_available_status_inventory_path(inventory, :employee_inventory => { :status => 'ALLOTTED' }) %>
<%= link_to 'Cancel', inventory_available_status_inventory_path(inventory, :employee_inventory => { :status => 'CANCELLED' } ) %>
<% elsif (inventory.employee_inventories.collect{|e| e.status == 'ALLOTTED'}) %>
<%= link_to 'return'%>
<% end %>
<% elsif inventory.is_available == true %>
<%= link_to 'Request for inventory',request_inventories_inventory_path(inventory, :employee_inventory => { :employee_id => current_employee, :status => 'REQUESTED', :inventory_id => inventory}) %>
<% end %>
In code when update status of employee_inventory to REQUESTED. Everything goes fine but after when I update status to ALLOTTED then second elsif condition is unable to execute.
from inventory.employee_inventories.collect{|e| e.status == 'ALLOTTED'}
Output:-
[true]
I am confused why is it not executing in second time. Please guide me. Thank in advance.
Aucun commentaire:
Enregistrer un commentaire