I'm trying to access a date variable from a form individually to the other variables. The form is a formtastic plugin form. The issue I am facing is that the date is a three-part dropdown and simply doing params[:friend][:born_on] doesn't seem to be doing the trick as it returns NULL.
Here is my parameters output;
Parameters: {"commit"=>"Create", "action"=>"create", "authenticity_token"=>"6+PyuqUNQySe29iEF69PIFvv6DOie5bp4jZAcRva85c=", "controller"=>"friends", "friend"=>{"born_on(1i)"=>"1973", "born_on(2i)"=>"3", "born_on(3i)"=>"5", "is_female"=>"false", "last_name"=>"Smith", "first_name"=>"John"}}
I want to use the variable to set another method; event.happening_on
Any help is appreciated- thanks!
The reason params[:friend][:born_on] is not returning anything is because that's not the name of the parameter.
It looks like the values you're looking for is one of: params[:friend]["born_on(1i)"], params[:friend]["born_on(2i)"], or params[:friend]["born_on(3i)"]. Which corresponds to what looks like, year, month and day respectively.
Related
I'm writing a form where some additional processing is required before sending the values. The image below depicts the simplified example.
where test_date and remind_date are saved on the server as a string of format YYYY/MM/DD.
However, the text field shown above allows users to enter an integer. The value from this field needs to be processed (basically, test_date - form_value).
I'm currently doing this conversion before sending the value to the server, within a saveForm() function that is triggered when the Submit button is pressed.
I feel like this might not be the ideal way, and wanted to get your opinions. Would it be better to handle this within the controller, by allowing a new param?
For a simple field like this you can just create another instance variable in the controller.
For more complex calculations or additional fields you could use a form object, eg: using the https://github.com/andypike/rectify gem or Reform.
I have a JSON that controller generates and in debug window it looks like this:
So basically this hash has two main elements, one is medications and one is query_duration. And medications its self is has a few members.
To draw some charts I need to pass the whole Medications part of this to the Javascript, I used GON gem for passing to JavaScript. But my problem is that I don't know how to pass the medications part?
Should I say like #order_summary[0] #order_summary.medications ? none of them worked tho.
#order_summary['medications']
Should work.
I needed to create a input mask for a jQuery datepicker in my Rails app, where the first form field uses m/d/yy format and the datepicker populates a hidden input with the proper database format.
I was using SimpleForm, and so I extended my own input so that the input is preceded by the mask.
I got everything set up and when checking out the browser, it all just worked well before I thought I would be done.
The form ends up with two inputs for the same attribute, each with the same id and name. I never thought this would work. Checking the development log I only see one date getting submitted, the second of the two which is the one that has the proper format for the database.
Is this all okay? Should I take some extra steps even though this appears to work fine, and more importantly, can someone explain what's going on under the hood that results in this behavior?
Thanks!!
Rails uses the Hash params to store fields submitted. When you declare two or more inputs using the same name, it happens the same as if you do something like
h=Hash.new
h[:name]="foo"
h[:name]="bar"
Result is bar because the foo was overwritten. So the "winner" is always the field value which the browser last appended to postdata.
But if I where you, I would not rely on the browser that the second field gets appended at last.
I am using date fields in Orbeon form builder that should be prefilled with the current date (see http://i42.tinypic.com/erdjrb.jpg). When choosing a date by hand in the form, the date format in resulting XML model is set to "2011-07-12". But when not changing the default value of current-date(), then I get "2011-07-12+02:00". Does anybody know why the date format is different when I prefill it with current-date()?
Thank you!
The XPath function fn:current-date() by definition returns the date together with explicit time zone information. I assume orbeon just passes the function call to the XPath engine (Saxon i think). A quick workaround would be to format the result of current-date() using format-date(), for example:
format-date(current-date(), '[Y]-[M01]-[D01]')
Since i don't use Form Builder, i can't tell in detail, but i assume setting the config options how to format xforms:input controls regarding date and time values applies for form builder, too.
In rails , I met a question!
when i use the multiple select ,i don't know ,how can i get the all parameter values ,it likes
in javaEE,
String[] strs=request.getParameters("aaa");
so,who can tell me the method in rails to realize the function?
Thank you in advance!
You search for "params". See http://api.rubyonrails.org/classes/ActionController/Base.html#Parameters for reference (subsection #Parameters). You can access the "aaa" parameter (GET/POST) using params[:aaa].
If you have a multi select in your form that value will just be an array of those values.