View terms and conditions without losing form inputs? - ruby-on-rails

I have a form that allows users to view some terms and conditions, which causes them to leave the current page. When they come back, the form is blank.
How can I store their inputs so they don't lose what they've already entered?
I would rather avoid popups if possible.

You could make the link to the Terms and Conditions open in a new tab/window (target="_blank"), or you could use a modal dialog to overlay the Terms and Conditions info in the same page.
I don't know Ruby/RoR though.

If the term and condition is mandatory, why don't you load it in the first place and then you can easily manipulate it using lightbox/fancybox or simple javascript.

Related

f.select - disabling option based on the first one selected in Rails

I have a form in which user can select two players from a list (two separate select fields). I managed to do it using options_for_select helper, but
user shouldn’t be allowed to select the same player twice - it obviously can't be something like player1 vs player1. I was experimenting with ‘disabled’ option, but without success, because list of available users should change dynamically after selecting first user, which probably can't be done in Rails?
This is a very broad question, with little details, hence my answer will be generic to cover the majority of cases.
You'll have to use JavaScript to hide the same options from the other list. Rails works server-side, therefore you should reload the page if you want Rails to re-render the list without the selected option. But this is a terrible user experience.
However, you should also perform a server-side check. Even if you add the JS in place, it will still be possible to send a crafted request where the players are the same. This is something that must ultimately be verified at server-side level, in your Rails controller or wherever you have the logic to handle the comparison.

Is it possible to have options on select change from when other select changes without javascript

There are a bunch of question on this but no answers on how to do it without javascript.
If you have one form that has 2 select boxes. The second select box has different options based on what you choose for the first select box. Here is a js example. Not all users have js enabled so for these users this option would be unavailable.
Can this be achieved solely using CSS3, HTML5 and Ruby? I would show what I've got so far in trying this but I got nothing.
What you are asking is how to manipulate the DOM after it has loaded without a client-side scripting language. This is not possible as far as I am aware; unfortunately that is not what you want to hear.
The proper solution in this case would be to have the user submit the page and generate the second selection box at that time. You will have to rely entirely on server-side logic to handle the problem. So basically something like:
Serve a page with just a single selection box
When the page is posted generate a similar page where the first selection is locked and display a second selection box with the possible options.
Continue the iteration until you have all of the required selections filled out by the user.
Serve the result that the user requested.

Rails - manipulating data in popup

I'm new in Rails, I have a Meal model which has many Products. Meals are assign to User (maybe this is important for a concept). In meals/new.html.erb I want to create new Meal as follow:
Click the button "Display Products"
On the same page (meals/new.html.erb) open modal (pop-up) with all products assigned to current user ( I have help method for current-user). It should be displayad like a list or grid with checboxes for example.
Then user can check few products and click "Confirm".
After that in meals/new.html should be appeared list of chosen products with additional input to fill their quantity.
So I have two problem here.
How should I display modal? Is needed any Ajax (I'm not so familiar with this technology)
How can I pass products between view and modal?
Could you help me a little to achieve these goals?
Regarding your first problem, displaying the modal is fairly straight forward. Essentially you will create a div with the proper bootstrap classes to be hidden when the page is loaded, and then create a button that makes it visible. I would recommend either reading over the W3Schools entry on modals, or from the appropriate part of the bootstrap javascript documentation.
Regarding your second question, this depends on exactly what you mean. The modal is part of the view, so if you're only trying to put information that is currently on the modal back onto the "page" behind it, you can do so fairly simply with javascript (copying content out of one element into another, or updating states of inputs). If, on the other hand, you're trying to use the modal to retrieve information from the server (for instance if you wanted to show a list of possible options, and then display detailed information about the selected items from the database) that would require Ajax.
If you have any snippets of code that aren't functioning as you expect, feel free to add your View to the question. In cases like this, usually the best way for us to provide help is for you to take an early crack at this, post the relevant code, and then seek answers for the things that behave unexpectedly.
I hope that helps.

In MVC, do I have to implement a custom error filter to redirect the user back from an error page?

For usability reasons, I have the requirement that an error page should tell the user something on the lines of
Sorry, we could not find this product in our database. You can go back to the previous page or search for a different product.
where the go back link is supposed to provide the same functionality as the back button.
I tried implementing it using Request.UrlReferrer, but it was a null in the smoke test. I found an answer here on SO which says that the browser can be set to not send it and
Bottom line is that you shouldn't trust it. Just append the url to the GET string and redirect based off that.
But as this view is displayed by using the default exception handling filter of MVC, I cannot append this in my code, as it does not send the user to the view in the first place.
Do I have to write my own exception handling filter if I want this functionallity, or is there a simpler way to do it? If I have to write it, what are pitfalls to look out for? It is possible that we will drop the link requirement if this means a substantial increase in the complexity of our code and just let the users click their own back button, but I don't have the experience to make an estimation.
I recommend solving this with JavaScript. Try
window.history.back()
As the onclick event for your anchor tag.

Rails: handle large menu lists

I have very large menu lists, that appear on every single page and also need to be updated according to user input. Additionally, I have live search implemented, to dynamically filter these lists.
What is the best approach to handle those in terms of performance?
I using a managed search service might be a good idea for your case. Or add indexes?

Resources