I want a search field to start outputting results once a user statrs typing
Here is what I got so far
<%= observe_field 'keyword', :frequency => 0.5,
:update => 'results',
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')",
:url => { :action=> 'search_results' } %>
then in my controller this is what i got. The text field is within a form i dont know if that makes a difference.
def search_results
keyword = params[:keyword]
#tutors = Tutors.find(:all,:conditions => ["category LIKE ?", '%' + keyword + '%'])
end
If I understand your question correctly your action is not receiving the keyword as expected. Is this right? If so then it's because you need to add a :with argument to your observe_field call. Like this:
<%= observe_field 'keyword',
:frequency => 0.5,
:update => 'results',
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')",
:url => { :action=> 'search_results' },
:with => 'keyword' %>
Related
I have a rating form with 5 radios and a submit button in it. The problem is when I visit this page, for some reason it tries to submit the form (with 'zero' values, of course). Validations don't let to do this, so it renders error message, which is not pretty.
Rating form:
= simple_form_for #shop.ratings.find_or_create_by(user_id: user_id),
:html => {:id => form_id,
:class => "star_rating_form"} do |f|
= f.hidden_field :shop_id, :value => #shop.id
- if signed_in?
= f.hidden_field :user_id, :value => current_user.id
= f.input :stars,
:label => "",
:collection => [[1], [2], [3], [4], [5]],
:label_method => :last,
:value_method => :first,
:as => :radio_buttons,
:item_wrapper_class => 'inline',
:checked => true
= f.submit
Ratings controller:
class RatingsController < InheritedResources::Base
belongs_to :shop
actions :create, :update
def create
#shop = Shop.find(params[:rating][:shop_id])
super
end
def update
#shop = Shop.find(params[:rating][:shop_id])
super
end
private
def permitted_params
params.permit(:rating => [:stars])
end
I tried to do like super unless params[:rating][:stars] == 0 however, it didn't help.
PS For the rest the form works fine.
I am not sure but is this bcoz you are using find_or_create_by which is right away creating object, try find_or_initialize_by. Or look in javascript somewhere you specified function onload() { form.submit(); } is specified. Hope it may help
I am working in rails 2. I want to make an link_to_remote object and render it on html page. I want to send date via ajax. I am trying this.
render :text => "<font color='"+ color +"'>" +params[:ajax_status] + "</font>" + <%= link_to_remote '| Undo',
:update => 'status_'" +params[:ajax_status]+ ",:url => {:controller => 'requests', :action => 'action_on_punching_request', :id => "+ params[:id] +" :ajax_status => 'Undo'} %>
But unable to proceed. It shows on webpage
Accepted<%= link_to_remote '| Undo', :update => 'status_'Accepted,:url => {:controller => 'requests', :action => 'action_on_punching_request', :id => 20 :ajax_status => 'Undo'} %>
PLease help me out.
You don't need the <%= %> tags, in this case - they're for erb.
Try just:
render :text => "#{ content_tag :font, params[:ajax_status], :color => color }#{ link_to_remote '| Undo', :update => "status_#{ params[:ajax_status] }", :url => {:controller => 'requests', :action => 'action_on_punching_request', :id => params[:id], :ajax_status => 'Undo'} }"
The easy way from our page is
welcome-controller add an email -> second_controller create an new object with the E-Mailadddress.
we have a welcome-controller that shows our welcome-page. At this page you can type an e-mailaddress which will give to an other controller. We work with simple_form
If we that this config.browser_validations = false and enter an "normal" text we get an error on the create action. In the older version, without simple_form we get an validation-error.
If we enable this we get the html5 validation. but when the browser doesn't support html5?
Our model is here
validates :owner_email,
:presence => true,
:format => { :with => /\A[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]+\z/ },
:on => :create
Our welcome-view is here
<p>
<h2>Create a list without registration.</h2>
<%= simple_form_for([#list], :html => {:class => 'well' }) do |f| %>
<%= f.input :owner_email, :label => false, :placeholder => 'Your Email.' %>
<%= f.button :submit, "Create", :class => "btn-primary" %>
<% end %>
</p>
Our create-action from the second controller is this
def create
# create a new list and fill it up
# with some default values
#list = List.new(
:title => "List",
:description => "Beschreibung",
:owner_email => "test#domain.com",
:admin_key => generate_admin_key)
#list.update_attributes(params[:list])
respond_with(#list) do |format|
format.html {#
redirect_to :action => "admin", :id => #list.access_key, :status => 301}
end
end
What have we to change that we get errormessages in the html4 version? can everyone help us please?
Just add a :message parameter. Unless you changed simple_form configuration, message errors should be shown on the right side of the field with errors.
validates :owner_email,
:presence => true,
:format => { :with => /\A[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]+\z/ ,
:message => 'Invalid e-mail! Please provide a valid e-mail address'},
:on => :create
I am using activeadmin with a range field :
ActiveAdmin.register Card do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Traitements" do
f.input :treatment_chlore, :as => :range, :in => 0..10, :step => 0.5
end
f.buttons
end
end
I have the slider showing well but i don't see the value of the slider. When we move the slider, i want to see its value on a :hint.
How can i do that?
I needed the same thing -- here's how I ended up solving it (only tested on Chrome. YMMV)
(I'm not crazy about the inline javascript handler here. If anyone has a better solution for use with active_admin, please comment.)
ActiveAdmin.register Card do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Traitements" do
f.input :treatment_chlore, {
:as => :range,
:in => 0..10,
:step => 0.5,
:html_input => {:oninput => "card_treatment_chlore_output.value = this.valueAsNumber",
:hint => %Q{value: <output for="card_treatment_chlore" name="card_treatment_chlore_output">#{resource.treatment_chlore}</output> }.html_safe
}
end
f.buttons
end
end
f.input :discount_percent, :as => :range, :in => 0..100, :step => 0.5
coffeescript file:
$ ->
text = $("label[for='frequency_discount_percent']").text()
$("label[for='frequency_discount_percent']").text("#{text} (#{parseFloat($("#frequency_discount_percent").val()).toFixed(1)})")
$("#frequency_discount_percent").change ->
$("label[for='frequency_discount_percent']").text("#{text} (#{parseFloat(this.value).toFixed(1)})")
So i have changed the value of label, seems not bad at all
Is it possible to submit another parameter outside the form data in rails? My problem is that I render different forms for different classes and send them to the same create method. I would like to send the class with the form (as value not as key in the hash).
Something like the :type parameter (that actually doesn't work)
<%= form_for(#an_object, :url => { :controller => :a_controller, :action => :create },
:type => #an_object.class.to_s.underscore) do |f| %>
The post message looks like:
{"commit"=>"Create Class of an Object",
"authenticity_token"=>"/iqu0A8/AocDT3HyjL5/+bKZiLkyr4FE71u/mc8Wx0Y=",
"utf8"=>"✓",
"class_of_an_object"=>{"name"=>"a name",
"description"=>"a description"}}
and I would have a "type" => "class_of_an_object", but directly in the hash an not within the "class_of_an_object" hash.
<%= form_for #an_object,
:url => { :controller => :a_controller,
:action => :create,
:type => #an_object.class.to_s.underscore } do |f| %>
And I prefer to use named routes
<%= form_for #object, :url => object_path(#object, :type => "whtever"), :html => {:method => :post} do |f| %>
This works for me:
<%= form_for #foo, :url => foo_path(:type => "whatever"), :html => {:method => :post} do |f| %>