0

I'm developing my first web application in rails and I'm pondering whether this is a good or a bad way to implement a functionality.

This web application has a User and Guild classes. The objective is that the user answers a set of questions through radio buttons in order to match to a certain guild.

Because the Guilds have a continent location and each continent has countries, I have about 60 options each with a name and an id, there are also other shorter radio button questions with as few as 3 options. In total there are about 7 sets of questions, all of which are 'hardcoded' in the Views file.

My main concern is: is it a better practice to model the form's answers in the database since the Guild class has a field for each set of the questions?

I was thinking about registering the option and quering it to the database and return the matching guilds. But then I thought about the registry process of the guilds and how I would have to repeat the same options for them to match the model.

Also because the form would be the most accessed element of the webapp, wouldn't it hurt the performance if the application retrieved each of the options instead of beign hardcoded?

rdlf
  • 25
  • 5

1 Answers1

0

I would recommend using a gem called simple_form. It makes building forms very simple.

And yes you should model it out and use form builders to help you.

You would do something like this

simple_form_for(@user) do |form|
  form.input :some_attribute
  form.collection_radio :guild_country, [collection of countries]
end

Something like that on top would do it.

Here is the simple_form reference https://github.com/plataformatec/simple_form/

And if you need all the countries use a gem called Carmen https://github.com/jim/carmen

YaBoyQuy
  • 783
  • 5
  • 8
  • Thank you for your response! I have looked at simple_form and it looks really usefull and simple, I will give it a try. If it is not too much to ask, could you please clarify me the rationale for creating a model?, I don't quite see the purpose of creating a database for the forms unless simple_form only generates the model for the rails framework. I'm thinking about how I will have to repeat some of the text used for the form in order to fil the values on the guild table, do you have any recomendation on how could I reuse it? – rdlf Aug 11 '12 at 08:34