Rails - Check Boxes Calling Methods - ruby-on-rails

I'm making a 'check_list' for my company. Each row of the table will be ONE event with 10+ check boxes that are labeled with the table header. Each time a check box is clicked I want to save that user's ID and Date. Is there a way to call a server side method to save this without submitting a form?
I just don't want to use a submit button because I need as much room as possible for check boxes.
I welcome any ideas or tips/tricks.
I am using Ruby on Rails.

Use jQuery, attach to the change event, and use ajax to call the method.

Related

Rails ajax post from button that sends values from outside of the form in the request

I'm somewhat new to rails and am wrapping a GUI around a CLI tool to give some non-technical users some self-service. Part of the tool contains a page where the user selects a few values from some drop downs etc, and then clicks one of a few buttons on the screen to kick off their desired actions. The fields where they make their selections are outside of the forms that the buttons belong to. On button click, I want to call a javascript function that will grab the values the user selected, and post an ajax call back to the server to run the command corresponding to the button, and then when the request returns I want to insert the command output into a text area.
The only problem I'm having is with getting the values of the fields outside of the form generated by button to, and including them in the ajax request. Outside of rails this is pretty trivial, but I'm having a hard time getting this to work. Does anybody have any suggestions or examples?
Thanks
There's really no need for what I was trying to do... it ends up I can just use the form_tag helper and multiple submit_tag helpers to create the submit buttons with different values. See this post for details: How do I create multiple submit buttons for the same form in Rails?
Also, here is a great write up on the javascript portion (it uses coffee script, but I didn't have any trouble following it even though I'm using jquery): http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html

Disable Auto Shipping Update in Magento Admin

If you've used the Magento admin, then you know that when you tab between the "Shipping Address" order screen it's kind of buggy. It does an AJAX call behind the scenes anytime that any field is updated. This keeps the shipping up to date, but its very annoying when trying to key in orders. Does anyone know a good way to disable this automatic functionality, so that it could be done with a button, instead of happen "automagically"?
I can't point to anything specific at the code level, as I don't have the code handy to look at just now, but I know it won't be easy per-se.
You will need to find and rewrite (unless it's all in the templates, then you'll need a custom admin theme) the block which generates that form, strip out the calls which add the handlers to the onblur events. Theoretically, your button should be able to call the same JavaScript method which is called via the onblur of the form elements.

Concept for a grails app

I am working on a Grails project, its an accounting project. We have multiple clients and they can have multiple types of accounts. I have to create the 'create' page for client, there should be a way to add multiple types of account to the client.
So I was thinking of making a drop-down list with account types and few text boxes to enter account name and other info about account. Also, as a client can have multiple accounts, so I want to create a 'add' button, when clicked it would display a new row to add a new client. I have done this kind of UI before using javascript but in this case, as there is a drop-down list and other components, I think it would be very hard and may not work.
I was thinking of creating a partial view which would render each time user clicked the 'add' button with additional row, problem with this would be during validation errors, edit page and i would also have to pass all values each time user clicks 'add' button.
Is there any other for doing this?
For the template approach you must use ajax if you don't want to carry on the params that the user has already set.
It is possible to make new drop-down lists appear (or any group of elements inside a <div>) when a user clicks a button, since Grails already comes with jQuery you might want to take a look at the .clone() method.
The problem with the two listed approeaches is that it will be possible to have duplicates.
Now, another option is to use checkboxes, so you can check just the type of account you want.
But to be honest it does seems a bit odd or even inapropiate to let the user choose the type of account he wants with such freedom.

On textfield focus set session[:something] in Rails

In Rails I have a form with text fields inside it. When I click on one of them I want to set session[:something]. Is this possible?
Yes, by making an Ajax call back to the server.
What's the purpose of setting the session here?
Are you trying to pass some information back to the server?
If yes, then you can add hidden field(s) within the form, that you can set programmatically when you respond to the click. The data within these fields will then be POSTed back to the server when the form is submitted.
If not, then you can just use cookies. In which case you can use something like http://plugins.jquery.com/project/Cookie or http://pastie.org/1986824 to work with cookies. Note that cookies are also available on the server side (but are not meant to be for storing large amounts of data).
If you need to pass back information to the server immediately, then use an AJAX call. Some examples are available here (using jQuery): http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/.

Parameters through postback

I'm working with Ruby on rails 2.3.4 and I'd like to pass some parameters from one page to another ones the first one is submitted.
For example:
On the first page, I have a form that when it's filled a Preview button can be clicked to check all the info entered before submitting the form. That button redirects to another page with the info entered before, but I don't know how to get it in the second page.
There are two possible solutions:
You can emulate the stepped form filling by creating a record in first form and saving it with status "unverified" or "pending". This way you won't have to deal with hidden form fields in 2nd and 3rd pages. All you'll need to pass is the id of pending record. You'll just need to update record status to "active" once the data is confirmed.
Use client side paginated from (all popular JS frameworks have plugins for this). Hence you will only display different <div>s in single loaded page (something like an interface for a setup wizard).

Resources