Ruby on Rails: How to purge entries from search box - html

I am using a search box using the following form:
<div id='search-box'>
<%= form_tag "/search", :method => :get, :id => "search-form" do %>
<%= text_field_tag :q, params[:q], {:id => "search-text", :placeholder => "SEARCH FOR PRODUCTS"} %>
<%= submit_tag "Go" %>
<%end%>
</div>
The problem is that whenever I type something in the search box, it shows a dropdown with previous queries. I do not want to store the queries and show the dropdown. How can I purge the queries?

use autocomplete="off":
<%= text_field_tag :q, params[:q], {:id => "search-text", :placeholder => "SEARCH FOR PRODUCTS", :autocomplete => 'off'} %>

Related

How do I get select_tag to display text in front of the parameter?

I want to display "Year: " inside the 'year' dropbox shown in the image below. How do I append text to the parameter field?
I'm using a select_tag as shown below:
<%= form_tag results_path, :method => 'get' do %>
<%= select_tag :season_year, options_for_select(#tournaments.order(season_year: :desc).collect{ |u| [u.season_year] }.uniq, session[:season_year]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<%= select_tag :tournament, options_for_select(#tournaments_filtered.order(tournament_date: :desc).collect{ |u| [u.lake_name, u.id] }, session[:tournament]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<%= select_tag :table_select, options_for_select(#result_options, session[:table_select]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<% end %>
You can use the include_blank option to add a dud option.
ie add include_blank: "Year:"
See docs for more details

default rails text area value with simple_form

I want to set a default text_area value.
<%= f.text_area :observations, :value => partner_setting.observations, :class => "tinymce", :rows => 4, :cols => 120 %>
But the field displays the same default text after replacing the content and returning to edit.
How can I reset it after create?
Thanks!
If you want the text to persist on focus, try this instead:
<%= f.input :message, input_html: { value: 'hello hello'} %>
You will need a placeholder, otherwise it will erase your content.
<%= f.text_area :observations, :placeholder => partner_setting.observations, :class => "tinymce", :rows => 4, :cols => 120 %>
thanks for suggestions, I solved this issue through a helper method which takes 2 params (passing them from the view):
def offer_settings offer, key
offer.send(key) || offer.partner_setting.send(key)
end
view:
<%= f.text_area :offer_greeting, :value => offer_settings(#offer, :offer_greeting), :class => "tinymce", :rows => 4, :cols => 120 %>

Rails+Facebox: pop-up-window doesn't work

I followed the source code form the rails3-devise-bootstrap-example to get my devise-login-page (that normally - without AJAX - works fine) in a popup window.
When I click on the login link nothing happens. The logfile tells me
Started GET "/facebox/fb_login" for 127.0.0.1 at 2014-01-09 19:15:0
Processing by FaceboxController#fb_login as JS
Rendered devise/shared/_links.erb (3.0ms)
Rendered devise/sessions/_new.html.erb (1155.0ms)
Rendered facebox/fb_login.js.erb (1251.0ms)
Completed 200 OK in 1509ms (Views: 1508.0ms | ActiveRecord: 0.0ms)
But no login-pop-up-window appears.
Here is the login link in my index.html.erb file
<%= link_to 'Login', fb_login_path, :remote => true %>
That starts my fb_login.js file
$.facebox('<%= escape_javascript(render :partial => 'devise/sessions/new') %>')
and should open _new.html.erb that looks like this:
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, :required => false, :autofocus => true %>
<%= f.input :password, :required => false %>
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
but it doesn't. What went wrong?
I got the answer by myself . Under assets/javascripts I had to define
jQuery ->
$('a[rel*=facebox]').facebox()
# facebox - make modal
$(document).bind "loading.facebox", ->
$(document).unbind "keydown.facebox"
$("#facebox_overlay").unbind "click"
in a js.coffee file.

Rails collection_select custom name attribute

I have the following collection select which acts as a filter in a Rails app.
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>
This always generates a name attribute of the select element like name="doctor[id]" which results in the browser to ?utf8=✓&doctor%5Bid%5D=1, which is not quite readable.
How can I change the name attribute to just name = "doctor" or basically just remove the brackets from it?
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select
The collection_select method contains the parameters "options" and "html_options". "options" allow you to add specific information, like {:include_blank => 'All'}, but does not replace html attributes.
You have to add the name to the next hash, like this:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All'}, {:name => 'doctor'} %>
<% end %>
Have you tried:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, #doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>

Simple_form how to make accept terms checkbox inline

<p><%= f.input :terms, :as => :boolean, :label => false, :boolean_style => :inline %>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%></p>
It ends up looking like this
What is the best way to line them up on the same line.
Here's a rather simple way:
<%= content_for(:the_links) do %>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%>
<% end %>
<%= simple_form_for #user do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :terms, :as => :boolean, :label => content_for(:the_links)%>
<% end%>
Ensure the checkbox and text are small enough to fit in one row inside the container, then set display: inline; or float:left;
Try using wrapper_html like this:
<p>
<%= f.input :terms,
:as => :boolean,
:label => false,
:boolean_style => :inline,
:wrapper_html => { :style => 'display: inline' }
%>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%>
</p>