Rails: How to send hidden paramters in link_to - ruby-on-rails

I wanna do this in rails way.
<form action="/home/result" method="GET">
<input name="hidden-query" value="hidden-data" type="hidden" >
<input name="public-query" value="public-data">
</form>
I tried with
<%= link_to 'TO RESULT',home_result_path(public_query: public_data,hidden_query: hidden_data)%>
It shows hidden_query parameter in view's url.
What I wanna do is hiding hidden_query.
How can I do it? Thanks!

Related

Redirect after uploading to S3 from rails app

I have a simple file upload field:"
<form action="<%= #post.url %>" method="post" enctype="multipart/form-data" id="new_file_tag">
<% #post.fields.each do |name, value| %>
<input type="hidden" name="<%= name %>" value="<%= value %>"/>
<% end %>
<input type="file" name="file"/>
<input type="submit" class="btn btn-awaken btn-sm">
</form>
that I took from the S3 online docs. The only issue is that it redirects to the S3 object after upload rather than simply returning to the same page.
How can I change the form to accomplish this? I tried changing the form to rails helpers, but the upload would fail due to the automatic accept-charset="UTF-8" param.
The form should contain a field for the success_action_redirect option, which has the value of the URL you would like to redirect the user to following a successful post.
https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/PresignedPost.html#success_action_redirect-instance_method

I want to POST the content of a uib-timepicker angular-ui bootstrap tag

I would like to let the user pick a time using a uib-timepicker tag and POST the result to my server (with a submit button for example).
<form class="simple_form vertical_form"
data-type="json" id="my_form"
action="url_to_post"
accept-charset="utf8"
data-remote="true"
method="post">
<div class="field">
<uib-timepicker
name="my_time"
ng-model="event.my_model"
hour-step="1"
minute-step="15"
show-meridian="true">
</uib-timepicker>
</div>
<div>
<input type="submit" value="Validate" class="btn btn-success">
</div>
</form>
But when I check to content of the POST method it is empty (I don't get the "my_time" key as I would expect. I guess it is because a "uib-timepicker" does not exactly work as an input field. But I feel like there must be a way to POST the content of that tag.
Thanks for helping!
I solved this issue by adding hidden input elements with binding to the time picker:
<uib-timepicker ng-model="ServiceRestoredTime" name="ServiceRestoredTime" ng-change="changed()" hour-step="hstep" minute-step="mstep" show-meridian="false" show-spinners="false"></uib-timepicker>
<input type="hidden" name="ServiceRestoredTimeParam" value="{{ServiceRestoredTime | date:'HH:mm' }}">

Upgraded RoR application (2 to 3.2) handles form input strangely

If have a RoR application that I upgraded from 2 to 3.2, and everything eventually got fixed, but I have some strange behavior from a form_tag.
The form code is:
<%= form_tag '/public/checkem' do %>
<%= hidden_field "vals", value = picks.draw %>
<%= hidden_field "val_index", value = xcount %>
<%= submit_tag picks.draw_date %>
<% end %>
Where picks.draw is an array which, when executed in turn generates:
<form accept-charset="UTF-8" action="/public/checkem" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="ET8OgURJpwvnQ+18lK1xKaFXTBLMuMXVw4AoM/gVEYw=" /></div>
<input id="vals_6,16,45,54,60,15" name="vals[6,16,45,54,60,15]" type="hidden" />
<input id="val_index_5" name="val_index[5]" type="hidden" />
<input name="commit" type="submit" value="10/25/2013" />
</form>
The idea being that the hidden input (vals) contains an array of numbers. This value is then processed correctly as an array in the /public/checkem function, but when it gets re-rendered here:
<span class="elem" style="background-color: #b0b040; color: #000000;"><%=#xpicks[0]%></span>
where #xpicks[0] is the first element of the array
<span class="elem" style="background-color: #b0b040; color: #000000;">{"2</span>
It's picked up what looks like the start of a hash. When I look in the log file I see this line, which confirms that the array was changed to a hash when the form was submitted:
Processing by PublicController#checkem as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"ET8OgURJpwvnQ+18lK1xKaFXTBLMuMXVw4AoM/gVEYw=", "vals"=>{"2,11,42,64,74,2"=>""}, "val_index"=>{"1"=>""}, "commit"=>"11/05/2013"}
This all worked fine in version 2, but I cannot see where, or why the array gets passed as a hash.
Apparently the use of "hidden_field" is indicated when a model and "form_for" is used. If there is no model you should use "hidden_field_tag"

Styling a form_tag

I have the following form:
= form_tag '/posts', {id: "link-form"} do
= text_field :post, :link
= submit_tag "Add link", {id: "submit-button"}
, which renders:
<form accept-charset="UTF-8" action="/posts" id="link-form" method="post">
<div style="margin:0;padding:0;display:inline">
<input id="post_link" name="post[link]" type="text">
<input id="submit-button" name="commit" type="submit" value="Add link">
</form>
It seems that Rails automatically add another div in the second line:
<div style="margin:0;padding:0;display:inline">
This div inherits everything from its parents, and I can't get access to this div (such as assigning an ID) to change its appearance.
How I can access this div, or how to go around it?
Its div for hidden inputs with existing data.
You do not have to touch it.

Create a search page in ActiveAdmin

I'm using ActiveAdmin to deploy my project. And I had some problem when I was developing.
I had some database table, e.g: "Worker", "Product", "Task". I wanted to create a page to search on those table with many situation.
I created a simple page:
ActiveAdmin.register_page "my page" do
content do
panel "Search details" do
panel "By Name" do
render :partial => "form"
end
end
end
end
And this is _form.html.erb
<form action="" method="post">
<input type="text" value="" name="taskid">Task ID</input>
<input type="text" value="" name="productid">Product ID</input>
<input type="text" value="" name="workerid">Worker ID</input>
<input type="submit" value="Submit"/>
</form>
But I don't know how can I call a controller from a form? (which controller was defined)
And How can I render or show the result to the content area of "my_page" in Activeadmin from a controller?
Anyone may help me? plz!
Design the form such that it uses the existing active admin filters and displays the results accordingly. You may want to look at the HTML of your filter forms (using firebug), in order to get the required params, and the submit action. Here is the partial which I use to search my User model (constructed from user filters):
<div class="panel_contents">
<form method="get" id="q_search" class="filter_form" action="/admin/users" accept-charset="UTF-8">
<div class="filter_form_field filter_string">
<label for="q_email" class=" label">Search User Email</label><br/>
<input type="text" name="q[email_contains]" id="q_email" />
<input type="submit" value="Go" name="commit" id="q_submit" />
</div>
</form>
</div>
and displays the result in the existing format. You don't need to design new views for that.

Resources