How to change an attribute in the bank via a button

2

I'm creating a small college project in Ruby on Rails and I came across a problem: I have a table called Person and another call Tools . People have many tools and each tool is owned by one person.

I need to add a resource that enables the loan of tools among the people in the system. For this, I created an attribute called ' loan ' in the Tools table, which if it has the value 0 means that the tool is not lent and if it is 1 , that is lent. In the tool view, I created a button with the function to borrow the tool.

My problem is how to make this button change the attribute ' loan ' from table Tools from 0 to 1 and vice versa? Would anyone have a better solution?

    
asked by anonymous 12.06.2016 / 01:36

1 answer

1

You can do an action in ToolsController , where you will pass the id of the tool, in this controller you perform the action of lending.

I suggest that you instead of putting a loan attribute, put the user_id of the borrowed user, so you can better control this relationship. That is:

  • user_id with id == tool loaned to user
  • user_id without id == free loan tool

In the action you would only associate current_user with tool referring.

    
13.06.2016 / 14:31