I don't think this is too simple to use for Rails. You may want to
consider using Sinatra or a smaller web framework, but I wouldn't
write it in straight Ruby unless you want that experience.
As for how to do this in Rails, usually when you have a form it should
map to the "new" or "edit" controller actions. Here you are creating
tickets. The only exception is that if the ticket already exists in
the database you want to update the existing record. However, this
behavior still belongs in the create action because, from the
interface perspective, the user is still creating a ticket.
Whenever you're deciding whether a request should be POST (create) or
PUT (update), ask yourself this: if the user submits the same request
again, will the second request alter the database? When updating a
record you can submit the PUT request as many times as you like
without effecting the database much. In contrast if you submit a POST
request multiple times it will create multiple records. Here you're
incrementing a counter so the database changes each time the request
is submitted, therefore a POST (create) request is the right way to
The create action might look like this.
@ticket.increment(:count) unless @ticket.new_record?
Everything else would be standard RESTful controller actions.
Hope that helps,
On Mar 30, 10:18 am, partydrone <partydr...@gmail.com> wrote: