I have below view and controller. Though remote: true is mentioned, kaminari calls my method using http(using page refresh). Is there anything i am missing to make my kaminari links ajaxable.
In VIEWS:
<div id="paginate">
<%= paginate #user, params: {slug: nil, pgsz: 20}, remote: true %>
</div>
In Controller:
#user = Kaminari.paginate_array(#properties, total_count: #search_result.total_count).page(params[:page]).per(params[:pgsz] ||= 20)
I will be responding to ajax in my controller, but first it doesn't even make an ajax call.
This is usually because you don't have jquery_ujs loaded, check your app/assets/javascripts/application.js file, it should have these two lines (at least):
//= require jquery
//= require jquery_ujs
Related
I have some strange behavior happening with bootstrap datepicker in a rails form. I'm using form_for in a partial for edit and new. When editing, the calendar shows perfectly when clicking on the date field but when adding a new record, the calendar is covered over by a dropdown list containing about 6 dates recently entered via the form. The calendar control is also open under the list. I can see the right edge of it. Also, when I move the browser window around or go to another open app and then back to the browser, only the calendar is there...the drop down list disappears. So odd!
I've been searching for a solution for several weeks and have scoured the internet and the datepicker documentation but just can't figure this out. Any guidance appreciated!
Here is the text_field within my form_for.
<div class="field">
<%= f.text_field :visit_date, {"data-provide" => 'datepicker',
"data-date-format" => "yyyy-mm-dd", "data-date-autoclose" =>
"true"} %>
<%= f.text_area :location, placeholder: "Add visit location..." %>
</div>
I have the gem in my gem file as:
gem 'bootstrap-datepicker-rails', '~> 1.8.0'
I have the following in my application.js file:
//= require bootstrap-datepicker
And I have this in my application.css.scss file:
*= require_tree .
*= require_self
*= require bootstrap-datepicker3
*/
one of alternatif solution for your problem is to turned off autocomplete field, you can turned off html autocomplete from previous input with this command below
<%= form_for #your_data , :html => {:autocomplete=> 'off'} do |f| %>
I receive an error wrong number of arguments (given 1, expected 2..3) how can i apply it in a each loop ? I want to be able to edit it inplace in an each loop
<%= best_in_place s.message %>
application.js
//= require jquery_ujs
//= require jquery.purr
user.coffee
jQuery ->
$('.best_in_place').best_in_place()
version best_in_place 3.1.1
OR
Is there a more better way of implementing an inplace editing
best_in_place(object, field, opts = {})
See the arguments the best_in_place method expects to receive. You're passing only one.
object means an object or specific record.
field is the attribute which to edit - in your case it could be message.
options all the options it accepts.
Most probably you need something like:
<%= best_in_place #object, :message, as: :input %>
I wish to have a little search box, which will allow the user to search other users by name, with the results showing in the box in a sort of list. Much like how, on a site like amazon, you can type a search into the bar and it will have a dropdown, except on mine I am not doing "autocomplete" (at least not yet)
At the moment, however, when I try to search, it says "ActionController::UnknownFormat in ChatRoomsController#search_users", with an explanation:
ChatRoomsController#search_users is missing a template for this request
format and variant. request.formats: ["text/html"] request.variant: []
NOTE! For XHR/Ajax or API requests, this action would normally respond
with 204 No Content: an empty white screen. Since you're loading it in a
web browser, we assume that you expected to actually render a template,
not nothing, so we're showing an error to be extra-clear. If you expect
204 No Content, carry on. That's what you'll get from an XHR or API
request. Give it a shot.
So it seems to be saying that this isn't an AJAX request, but I have have pretty much copied my code from the RailsCast on AJAX searching (just removed some pagination bits), so this confuses me.
Here are the relevant parts of my code:
# chat_rooms/show.html.erb
<%= form_tag search_path, :id => "search", :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search for User", :name => nil, class: "button-butt" %>
<% end %>
<% for result in #users_results %>
<%= result.name %>
<% end %>
and the controller:
# chat_rooms_controller.rb
def search_users
#users_results = User.search(params[:search])
end
the model's search method:
# user.rb
def self.search(term)
where('name LIKE ?', "%#{term}%")
end
I think my routing is OK, but just in case it isn't:
# routes.rb
get '/search_users', to: 'chat_rooms#search_users', as: 'search'
and finally, the javascript:
#application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
$("#search input").keyup(function() {
$.get($("#search").attr("action"), $("#search").serialize(), null, "script");
return false;
});
Any help would be appreciated.
# routes.rb
get '/search_users', to: 'chat_rooms#search_users', as: 'search'
Since your routes.rb specifies that you will have a search_users action in ChatRoomsController and it(action) seems to be present.
When request arrived from the form, it landed on that action but, since the template named search_users.html.erb is missing, its displaying this error.
Solution
Either handle the request and respond with a template mentioned in the error message; or, rename and redesign the routes and controller.
Edit: 1
I just want to send the search request, and have the results pop into the list below the searchbar if you see what I mean.
If so, do following:
# chat_rooms_controller.rb
def search_users
#users_results = User.search(params[:search])
render :show
end
Plz comment, if its not helping.
I have a customer contact form in my app which, of course, requires a phone input. I am running Rails 3.2.13 and using Zurb Foundation. I am hoping to find a gem that offers an input mask in the form '(999) 999-9999' that I can call. My data is really local so the US formatted numbers is all that I need.
I am able to perform the validation on the field but wanted to keep the users within the tighter boundaries of an input mask. This is what I have at the moment.
<div class="large-4 columns"><%= f.telephone_field :phone, :placeholder => "Phone - (123) 456-7890" %></div>
Any great gems for this, or perhaps a jQuery plugin that you like?
Cheers!
-Edit
So here is the full answer for what I needed to accomplish. Just in case anyone is looking for a quick fix. This is the code in my _form.html.erb view file:
<div class="large-2 columns">
<%= f.text_field :phone, :id => "phone", :placeholder => "Primary Phone"%>
</div>
Here is the code in my coffee file in my assets/javascripts folder:
$ ->
$("#phone").mask("(999) 999-9999")
You need to download the appropriate jquery.maskedinput.js file from the link #vinodadhikary mentions below. Then you must require the file somewhere below the jquery file in the list of dependencies in your application.js file like so:
//= require jquery
//= require jquery_ujs
//= require foundation
//= require jquery.maskedinput
//= require_tree .
That's about it. If you notice anything amiss, please let me know and I'll edit.
I have been using the plugin http://digitalbush.com/projects/masked-input-plugin and it works pretty well.
I have a lot of fields with different masks so I use this method in my application coffescript.
$( "[data-mask]").each (index, value) ->
element = $(value)
element.mask($(value).data('mask'))
Now I can just set a data-mask attribute on any of my fields::
<%= f.text_field(:phone, data: { mask: '(999) 999-9999' }) %>
I hope this helps someone!
I'm using rails3-jquery-autocomplete gem to try to complete a form. However, I'm just getting no response whatsoever.
Alright, here it goes:
In my view:
<%= form_tag chats_path do %>
<%= autocomplete_field_tag 'name', '', chats_autocomplete_chat_name_path %>
<% end %>
In my ChatsController:
autocomplete :chat, :name
In my routes:
get "chats/autocomplete_chat_name"
And finally in my application.js:
//= require autocomplete-rails
Although I'm sure the javascript is at least loading, since I put an alert to let me know that autocomplete-rails.js was loading. Any ideas?
Try using chrome -> tools -> developer tools and open up the "networking" tab. Then try again and see if you're form is being sent and if so, what the response is.