I am currently working on a project called "Gradebook" which will be implemented in Ruby on Rails. In one of the pages in Gradebook, it is required that the instructor will be able to add, remove, or update an assignment.
I'm a beginner with Ruby on Rails, so I went through a couple tutorials and realized that I could simply define "assignment" as a resource in the routes file. The only issue I have with this approach is for each CRUD operation, there is a specific URL associated with it (ex: "/assignment/new" or "/assignment/:id/edit"). However in my case, I want to be able to carry out multiple CRUD operations in a single view.
My idea was to have a single controller action associated with my view. The view would contain multiple submit buttons that would be named "Add", "Remove", and "Edit" respectively. The value of each of these submit buttons would be passed to the single controller action, and code would be executed depending on which value was passed. For example:
def my_view_name
#So all assignments can be viewed in a table
@assignments = Assignment.all
if params[:commit] == 'Add'
#Save assignment to database
elsif params[:commit] == 'Remove'
#Remove assignment from database
elsif params[:commit] == 'Edit'
#Update assignment in database
end
end
But would this be the best way to implement the ability to perform multiple CRUD actions in a single view?