I have a problem about the nested forms, which I've survey for some possible solutions (Nested form gem, Railscasts) but still have no idea to implement it.
My question is totally based on the solutions above, so please read it if you need :)
Now, my question is:
If i want to add/edit "only one" Question(and it's Answers) per page after I "create/edit" a Survey how could I make it?
In other words, there is only one Question(but could have dynamic numbers of Answers) fields, in the "create/edit" Survey page.
And how to make
add another question,
edit previous question or
remove current question
functions.
I've try to solve this by 2 ways, one is using javascript to hide the previous question each time I add a new one, but in this schema, I can't make my way to edit the existed question.
Another is using Ajax, but ... I have no idea with it.
Related
Please could you help me to think about how best to layout a form.
I have a series of checklist boolean questions (for example, do you want data?). If the answer is yes, I want to show questions further relating to data.
I have a form with the series of boolean questions and another form with the follow up questions to be shown if the answer is true at the top level.
How do I go about revealing the detailed follow up questions if the answer at the top is true?
I tried if true then -- a link to the follow up form, but I'm either expressing it incorrectly or approaching the layout all wrong. I've seen some questions in this post describing methods to help with the reveal, but I don't follow the reasoning behind why.
Thank you.
It sounds like you will need a large nested form, or multiple smaller forms.
You have 2 simple options:
Use Javascript to hide/show nested questions when some checks a box. here is an example: https://stackoverflow.com/a/6358754/1536309
Create a wizard! think about how your form can be completed in a few stages instead of at one time. https://github.com/schneems/wicked this is a good gem for building wizards. You could have each checkbox and its related information be a stage in the wizard, then the last page would submit the entire form contents.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the best way to structure a multi-page form to create and edit models in a database?
Is there a "Rails" way of breaking down a large form for a model into multiple steps?
For example, in my HR software, User model has many attributes such as experiences, educations, addresses etc. It would be overwhelming for the user to see all these forms in one page. I would like to break them into pieces and present them step by step instead.
Is there a preferred way of doing this in Rails?
You have two way to do this
1) Using Multistep Forms
2) Using Wizard
You can use state_machine to create multiple step form. Here you can write validations for each state where each state can be assumed as each step in your case. Hope this helps you.
First time posting in Stack Overflow, hope I'm doing this right.
I'm writing an app with Ruby on Rails right now. Without disclosing too much, the premise is that we have organizations and normal users. Organizations have events, which require users to answer a questionnaire before participating.
I'm pretty sure about these models / relationships that I will be using (this isn't really that important/pertinent to my question i think, but just wanted to give background):
organization (one to many) events
event (one to one) quesitonnaire)
questionnaire (one to many) users
(specific) response (one to one) user
The part I have a question about is how to implement the questionnaire. I want to give the ability to Organizations to essentially write / build their own forms. I'd like to stay away from them using code if that's possible (ie any DSL and whatnot).
I suppose the easiest way to do this is to give them a set number of text-area responses, so that I can consistently store the data and don't have to hassle around with how to configure storing this data (for example, maybe each event can only have exactly 5 responses to be filled in by textfield response by the user).
My ideal would be for the organization to be able to dynamically generate the forms on their own - maybe one questionnaire will have 1 text input, followed by 3 multiple choices, and maybe 2 short answers at the end; another one may have 5 multiple choices, and 1 short answer; yet another questionnaire might only have 1 text input...you get the idea.
So I see two parts of this problem - the first is the user interface for the organization to create the questionnaire. i'm imagining this wouldn't be terribly hard - ask them how many of each response type (MC, short answer) they would like to put into the form, give them the ability to rearrange them, etc.
The second part of the problem (what I'm more concenred about) is how to store/access this data. I'm guessing there's no dynamic-attribute sort of deal in ruby - storing some field with an unspecified number of parts and whatnot. i suppose i could make them all individual models (ie a question_response model, with :question, :response_type, :response, etc), but I'm fairly certain that's probably inefficient.
My initial guess is probably to serialize the data / use json; I worked briefly with Drupal 6 and this seems to be the way they did it. I was wondering if anyone else had any experience / suggestions though? I'm pretty new to Ruby so I was wondering if there's a gem out there or something that would help with what I'm trying to do.
Thanks!
You might want to look at the Surveyor gem
http://vimeo.com/7051279
*slightly old how-to video
https://github.com/breakpointer/surveyor
Surveyor does come with it's own DSL which is relatively easy to use (although can be abit restrictive at times). The data is saved as a set of question - answer values, so there is no actual specific model (beyond Surveys -> Questions (question_groups) -> Answers).
Originally I did look at having people submit their own Surveyor DSL specs - which would then be used to generate the actual survey via a Rake command.
I think if you need to build a dynamic model (and save the data) it is possible, although I am not not sure if you'll be able to get the Rake tasks to run to build the actual tables in a dynamic way due to permission restrictions.
Have a look at http://ruby-metaprogramming.rubylearning.com/ and Metaprogramming Ruby: Program Like the Ruby Pros by Paolo Perrotta, for some starters.
I'm taking a "cloud computing" course and have a few problems that I am trying to work through for the final project. I'll preface this with saying that i know nothing about this subject, and the few powerpoints I got off my online class don't really seem to point me in the right direction.
Basically what i need to do is have a page that allows a user to create a evaluation form. I have a general idea how to do it but I don't even know where to start in rails, I was hoping there was some stuff that Rails would do for me that might make it easier.
My assumption is that I could create a form that would allow entries for section headings.
Then when one occurs I need to allow actual question entries. then the user has the option of adding questions for the section. Then the user may add another heading, and questions.
When this "process" is complete, I need to allow a 2nd user to actually use the form for entries.
I'm assuming I somehow need to make a "string' object that will hold the text that I'm setting up, and then it sets up entries for each question.
I'm clueless where to start, I'll probably be asking a lot of questions. I don't want the solution I just need to get pointers, heading in the right direction.
the first step I'm thinking is finding a way to allow a "command" to do the equivalent of this but in the browser from another form:
rails generate scaffold Evaluation Topic:string rating:string comments:string
Is there a way to "create" a scaffold of a form using rails in a web browser?
It seems to me that you are mostly concerned with created forms using Rails.
Railscasts has some awesome tutorials on forms: Railscasts
After viewing some of those, you should see that Rails follows an MVC policy (more information here).
Since you mentioned the scaffold, it creates several controller actions. One of those is "new" (also "edit") which I believe would be the equivalent of creating the evaluation form.
You could then create a controller action(s) for users to fill out the evaluation form.
These links should clear up a few of your questions and get you used to the rails terminology for better questions later.
Good Luck!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I've read the "Create Multi-Step Wizard" in Advanced Rails Recipes. I've also read and re-read the documentation for the updated FSM I'm using called Workflow, and looked here and here. The Advanced Rails Recipe focuses on records (quizzes) that already exist, and doesn't cover creating new ones. The Workflow docs don't cover any code for controllers or views, so I've no idea what to do with all this model magic, and the last two links barely touch on implementation either. From the aforementioned resources, I have a good understanding of what a FSM in Rails is and how to play with it in the console or IRB, but I've got very little direction or understanding how to implement one into my Rails app.
What I would like is this: a simple, multi-step user signup process.
Step 1: User enters in their critical
details (with validations).
Step 2: User enters in their search
criteria, for their profile (with
validations).
Step 3: User agrees to the Terms of
Service (with validations).
Step 4: User is greeted by a
confirmation page, including a link
that takes them to their newly created
account.
I'd also like full navigation between the steps and full capture (saves to the database) with each transition.
Can someone please give me a clear implementation of something similar to this? I would LOVE an example app that includes a multi-step signup process where I can look at the code (FULL source code--models AND controllers and views) under the hood, but I've been unable to find anything like that.
Any guidance would be appreciated!
2020: How to do multi-step forms in Rails
TLDR; You create custom controllers that are just for the wizard flow that are separate from the normal created controllers and further you utilise ActiveModel to do validations along the way without needing to save to the database until the end.