I have a function to take ownership of a job which updates the database to update the username in a table row. I want to link to this function from the view and then redirect to the appropriate page.
How do you link to a controller function or a model function from the view?
from the index i want to have another link beside show, edit, delete, which says ‘take ownership’
This will then fire off an action in the application controller
def accept_job(job_type, id, username)
if (job_type == 'decom')
Decommission.update(id, :username => username)
else
end
end
You can use the instance variable
@controllerto get a reference to the controller. As for calling a model function, you can callModel.functionto call class methods, or if you have a particularModelinstance calledmodel_instance, then usemodel_instance.functionto call an instance method.Edit: Okay, I think I understand what you’re asking now.
You should
Create a new action in the controller, let’s call it
update_username:Add your action the routes in routes.rb. See Rails Routing from the Outside In for more details.
Add your link in the view: