rails best practice for a multistep form? - ruby-on-rails

I want to create a mutlistep form in Rails 3. I've watched the railscasts episode on it, but I did not feel like he was using the best practice when creating the form. I felt like it was a sloppy way to accomplish the task. What is the best way to create a multistep form using the best practices in rails?

Your question is a little hard to answer without more information, and a true answer would be a detailed tutorial (like a Railscast) rather than a SO answer, but here's some thoughts to get you on your way.
There are two major approaches to multistep forms:
Use Javascript to display the form bit by bit
Create separate views and use create/update or similar to route the user from one to the next.
There are advantages to each method, depending on whether you want to support javascript, and what your requirements are about saving data in between sections.
Advantages of 1
Faster for the user to navigate from section to section (javascript hide/show is instantaneous)
Data is easily accessible is the user wants to refer to an earlier section
Simpler controller actions
Disadvantages of 1
Will not work for users who are not running javascript (and no progressive enhancement is really possible here other than displaying the form as a huge chunk).
Will require you to provide javascript-based navigation to move from section to section (only a disadvantage if you're new to .js)
Will require AJAX if you want to save the user's information between steps.
Without AJAX and javascript, the user is at the risk of losing a lot of entry if the user accidentally pressing the back button, etc.

Related

Is active Admin a good fit for a complex admin interface for a daily deal rails 3.2 app?

I am building a daily deal app in Rails.
I just installed activeadmin gem which is really great and easy so that I can now create and monitor users. My need for creating and managing deals is quite complex:
I need to be able with the basic text fields (name of deal, date of deals, product name...) to add on the Deal's page stuff that for me (as a Rails newbie), i would associate more with a real CMS than with active admin, that is to say, i must add pictures (through url addresses on amazon S3), embed videos, associate features on certain deals such as vote up or down, and have a sort of html5 WYSIWYG html/text editor allowing me like i'd do on a wordpress site to move/add/arrange/re-position between each others texts, videos, sliders, call to action buttons, videos and much more.
I feel activeadmin is great for basic monitoring and maybe creation of objects for simple cases but as it works so much "automagically" I fear I won't have enough control or ability to bring many features and CMS stuff into active admin that i should build the "Deals admin Interface" on my own pages and not rely on active Admin for this.
What do you think about it ? Can I put all that stuff "inside" my Active Admin pages/controllers...or should I build it "outside" active admin ?
Thanks for your help!
any answer for this question will be subjective..
formally, you can override anything (views, models, controllers) in activeadmin very easily. all this cases have minimal but enough instructions in documentation
there are some difficulties to override look&feel for example with bootstrap to receive more responsive layouts but in general case AA is administration framework designed for generic backends so this feature is not critical
according to your question to manage forms it supports formtastic so you can use any power of this gem
you can override form with generic _form.html.erb in one line with form :partial => "form"
you can use html-editors like this or this or other (like this) out of the box
BUT
this moment always insensibly comes when you begin to understand that some features can be done much better without any gem (not only activeadmin)
the real question is when will you cross this line but it is only up to you..
my advice: try to imagine most difficult issue and implement it with activeadmin. if you solve it with activeadmin - you can try to use it in future. if not => ...
one more thing: you can look at rails-admin - it is very promising and competitive to AA

Rails Active_Admin VS. my own backend

I've been thinking of writing my own backend, because I feel active_admin might not support all the requirements.
I wanted to ask if Active_Admin supports any of these just to be sure:
I have a has_and_belongs_to_many relationship between my ad model
and tag model. In the new ad page I would like to have the form for
the ads, as well as all available tags so the admin can choose which
tags to associate with the ad. I was able to do that normally in my
application, but can I do that with active_admin?
Can I add custom buttons.. Like one to convert to PDF for example,
or one to send an e-mail..
Could I add some sort of before_filter, so the admin can only view a
model, but not edit or delete it for example?
Thank you.
All of those things can be done via Active Admin, but as it was pointed out, it can be quite a nightmare actually implementing certain things depending on the amount of flexibility you need it to have. For that exact reason, I decided to start rolling my own administration panels.
I have tried an implemented almost all robust gems for admin panels. I have also sweated over several hand-made ones.
Active-Admin is very usability centred, but it is not configuration centred.
As you rightly aniticipated, some of the more complex modifications can be tedious.
In my experience, rails_admin is the best middle ground I could find.
Take a look at it, it is highly functional, completely modular (made as a Rails 3 Engine) and simpler to modify.
If you can live without some details when customizing this is definitely the way to go. However, if you need to have everything just right, then there is not substitute for hand-made.

Evaluation Form Creation

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!

Symfony admin generator: To be or not to be?

on the last projects i've started, I wondered if I should use the admin generator or not. My usual choice is to not use it, as some developers suggested to me, "unless it's for quick backend prototyping and submission to client", they said. Currently i'm starting a project and i'm in the situation that the client need the backend very fast to start loading lots of data, and i'm doubting about using the admin generator or not. I would use it if needed simple form fields. But one of my models must have multiple images, and maybe I need a more complex view that allow the client to load N images, so the admin generator maybe it's not the best choice, but it seems fast, it seems to save time and that's what I need now, time saving!
The project is very simple, it's just a Product model with multiple images and multiple sizes and belongs to a simple category.
What do you think? What would be the best option for this? And where do you think that makes sense to use the admin generator or the regular module generator?
Thanks in advance!
Regards.
I use the admin generator as much as possible. It is really designed to be great for the "backend" of your website-- the administrative screens which authors and editors will use to maintain the app. Any module that needs to be user-editable and is simple cries out for the admin generator.
Recently I have been starting everything with the admin generator so that there's a working prototype to build data with. Then I select certain modules or views that need more magic sauce, and build them out with more customization.
Remember, you can add views and forms to an admin generator module. On my last project I used the admin generator for the "edit" action of my main object but added "show" methods similar to a non-admin-generator form-- adding an executeShow() action and showSuccess template.
The other thing to keep in mind is that the admin generator is only a generator. It writes a bunch of code for you in cache/frontend/env/modules, but you can override any of it by building the equivalent code in apps/frontend/modules/. If you find one part of it that you can't configure with generator.yml, you can copy the file out of the cache into your module dir and hack away. I prefer to take the "out of the box" admin generator as far as possible before customizing it, though.
i've been working with symfony for quite some time now and i've been using the admin generator for simply and complex situations. It's true that it saves time when developing CRUD modules, but i dont think that is not advisable for complex cases.
I think you should use it and also learn the power of customization the generator gives you. If you have complex Forms, leave that for form classes to manage and as you said, if your forms a quite more complex to render, well you should only take care of the rendering of that only segment of the view.
But, if you decide to make if without it, you should start thinking about creating all the view from scrap, that in my case takes quite time ( i'm not so versatile wiht css).
But this is only my opinion, hope this helps you make a more rational choice!

Rails, One Model, Many Screens

I have a model with many fields (nearly 40). The client wants the fields divided among multiple screens. The model also has a few has_manys that should look like they are part of the same model.
How can one divide the model, and what are the tradeoffs among the ways to do it?
I see a couple of possibilities:
1) Use JavaScript to show and hide parts of the form. I think I can make that one work.
2) Use forms that submit to different actions. Can form_for be used with appropriate options?
I'm looking for other ideas too.
Check out acts as state machine. You can use this to create wizards and whatnot.
Having reread your question, I think Javascript is really what you're looking for. Check out jQuery UI, they've got a tab component that will probably help.
I would check out the ActsAsWizard plugin. Makes doing a wizard like this extremely simple.
Check out the readme it is excellent.

Resources