ujs

jquery-rails breaks kaminari?

删除回忆录丶 提交于 2019-12-21 23:15:54
问题 I updated my Rails 3.0.7 application to use kaminari 0.12.4 (up from 0.10.4) for pagination and jquery-rails 1.0.9 and it seemed to break pagination. I've regenerated the kaminari views since they are different but for some reason ajax isn't working. <%= javascript_include_tag :defaults %> is included. Which produces this in the browser: <script src="/javascripts/jquery.js?1306353646" type="text/javascript"></script> <script src="/javascripts/jquery-ui.js?1306368501" type="text/javascript"><

UJS, AJAX, Rails 4, form_for collection_select to pass value into method and return value back to form

≡放荡痞女 提交于 2019-12-13 16:25:03
问题 I'm very new to Rails, and as such am having lots of of confusion when dealing with AJAX, UJS and Rails together. I've looked at railscast, several SO answers, tried #rubyonrails IRC channel on freenode. Alas, I'm still stuck. Anyway, here is my problem. SO I have two Models, Building and Property. Property belongs_to Building and Building has_many Properties. I've added the foreign key to Property as building_id. Now, in my building model, I have a Method: self.search(search) and given the

What's the best UJS way of refactoring link_to_function?

前提是你 提交于 2019-12-12 20:15:22
问题 I have the following interface for a baseball-draft oriented hobby project of mine that lets a team owner build a set of criteria to rank players on: Clicking the attributes will add that attribute to the list, give it an importance factor and a sort direction. In Rails 2 and Rails 3 (with the prototype helpers) - I did this by having the following: <div class="rankingvaluecloud"> <ul> <% @rankingattributes.each do |attributename| %> <li><%= add_ranking_attribute_link(attributename) %></li> <

doing a remote => true call with javascript

僤鯓⒐⒋嵵緔 提交于 2019-12-12 17:26:49
问题 Is there a way to have the same behavior as a link_to ... remote=> true with javascript? maybe it's not necessary - I have a div with the user's name and picture in it. I want to have the entire div to react to a click and go to the method ( users#show for example) as if it were a link_to. The problem with link_to is that it creates a href , making the text linkable etc. Also, I can't seem to use it to make the whole div clickable, only the text. In an attempt to explain myself more - If link

rails.js's purpose

岁酱吖の 提交于 2019-12-12 00:38:24
问题 I am getting acquainted with Rails 3, UJS and JQuery. I understand why jquery.js and application.js are needed but why is rails.js needed? 回答1: Think of it as the missing link between jQuery and Rails. Suppose you have a form tag, <form method="POST" action="/some/path" data-remote="true"> .. </form> The code that will look at the data-remote on this form tag and other such attributes used that Rails looks at, and submit this form through AJAX is handled by rails.js. It is like a connector

Async file uploads with Rails 4

十年热恋 提交于 2019-12-11 22:37:26
问题 I have a form that uses rails jquery-UJS to submit asynchronously. It works fine as long as there is not a file input. When I add a file input, the form stops submitting asynchronously, and instead submits normally (full page reload). I found out that since browsers do not support ajax files, UJS will fire the ajax:aborted:file event if a populated file input exists in the form. http://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs The proposed solution is to use remotipart. https://github

Rails 3 UJS dry Client + Server Side form validation

这一生的挚爱 提交于 2019-12-11 03:53:11
问题 Form validation with jQuery is as easy as adding a classname to a field. Form validation with rails is as easy as putting a condition in to your controller (and/or model). I figure there should be a way to write the validations once and have them applied both client and server side. I've always been a fan of writing my own javascript, but with rails3 unobtrusivity UJS might be well worthwhile here if it can accomplish this. Thanks!! 回答1: You should look at creating your own form builder for

How do I call a JavaScript function from an erb template?

雨燕双飞 提交于 2019-12-11 01:48:54
问题 If you define a JavaScript function and then call it from an erb template the function does not get called. Why? Clicking this link should show an alert, but it does not. = link_to "Add Sprout", new_sprout_path, remote: true Controller: def new @sprout = Sprout.new respond_to { |format| format.js } end Then in the template I call a function: # sprouts/new.js.erb doSomething(); The function is defined in my js files: # javascripts/sprouts.js.coffee doSomething = -> alert "yum ghum I am a new

rails sending the wrong content-type in ajax response

我们两清 提交于 2019-12-11 00:59:51
问题 I have been struggling terribly for the better part of the day with the following problem: I have a rails 3.1 app - running fine I am trying to add some ajax to it However, no matter what I try, Rails insists on sending the wrong content-type in the response header. #the form = form_for @signup, :url => '/signup', :remote => true do |f| = f.text_field :email, :class => 'email', :size => 26 = f.submit 'Notify me' #In the controller def create respond_to do |format| format.js { render :content

Rails, CoffeeScript and ERB

元气小坏坏 提交于 2019-12-10 18:55:48
问题 So I'm messing around witha few javascript responders for a few actions. So, for instance, def create #code omitted respond_to do |format| if @post.save format.html { redirect_to discussion_posts_path(@post.discussion), notice: 'Post was successfully created.' } format.js else format.html { render :action => "new" } end end end #create.js.erb $("#discussion_posts_table").append("<%= escape_javascript(render(@post)) %>"); $("#post_body").val(""); Now lets say I wanted to convert these