Rahul
Rahul

Reputation: 1876

Should I create an MVC model in this scenario?

I have a Ruby on Rails 3.2 application and use formtastic and client-side-validations gems.

I have a user, and TableReservation with standard CRUD operations, the validations for which work with the aforementioned gems.

:user              :has_many   :table_reservations
:table_reservation :belongs_to :user

Now I need to add a 'search' form for the user to get details on his table_reservation which takes in user.first_name, user.last_name and table_reservation.secret_token. I need to add validations which will prevent a normal user from submitting the invalid form.

I was wondering if I should create a TableReservationSearch model to keep working with the formtastic, client_side_validations gems as before. At the same time, it feels like creating a model for this is unnecessary since it is not stored in the database. But then again this model need not inherit ActiveRecord but include ActiveModel::Validations, etc. I can also write a simple form and use a jQuery validations plugin or something similar.

So I am confused about when to create a model for such purposes and when not to!

What is the best way of approaching this subject?

Upvotes: 0

Views: 72

Answers (1)

Arpit Vaishnav
Arpit Vaishnav

Reputation: 4780

I think you are looking for nested field validation. Please look to this issue. Maybe this will help you. And there is no need to create a model for validating nested fields on the form. And on the validation code you can add an action too.

Upvotes: 1

Related Questions