rjs

How to replace the div in Rails 3 using AJAX?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 08:41:33
问题 I was trying to replace my div in DOM using RJS. Here is the code i tried, The controller has this method: def change render :update do |page| page.replace(:test_id, :partial => "input",:locals =>{ :type => 'text', :name => 'user[user][contactinfo][city]', :val => "", :size => '244', :placeholder_text => 'Yes it is working...'}) end end The view contains: <div id = "test_id"></div> <%= link_to "AJAX", "/poc/change", :remote => true %> Now I want to replace the div id="test_id" with the

How to reload a div using render(:update) and replace_html?

二次信任 提交于 2019-11-30 19:03:25
问题 How to reload only the div id on a page? I just need to reload a certain div. in my controller I have def mycontrolleraction ... render(:update) do |page| reload_only_the_div('adiv'), :controller => 'my_controller' end end Is this possible? 回答1: You can replace a div's content with a partial like this. render :update do |page| page.replace_html 'person-45', :partial => 'person', :object => @person end Where the div id is person-45 the partial's name is person . Also you can pass an object to

Ajax pop up box using Ruby on Rails

一曲冷凌霜 提交于 2019-11-30 15:41:24
This is a pretty basic question but I can't find a good answer for it. I have a page in my Rails app where there are many objects that can be 'flagged'. Clicking the flag button should display a little box with a confirmation, little form, etc. The trouble is I can't figure out how to do this using RJS templates. I've been using page.insert_html but this requires an ID. In order to make this work I had to assign each thing that can be flagged a unique ID. This doesn't seem very clean and still leaves me wondering about making sure only one form can be displayed and that the box disappears on

Rails 3.2.2 not executing rjs

試著忘記壹切 提交于 2019-11-30 15:03:01
问题 I'm following the book Pragmatic Agile Web Development With Rails 4th Edition , BUT I'm using Rails 3.2.2 instead of 3.0.5 as recommended in the book: ~$ ruby -v ruby 1.9.3p125 (2012-02-16) [i686-linux] ~$ rails -v Rails 3.2.2 I got stuck when including AJAX to redraw the Cart without reloading the page. Here is the create action in line_items_controller.rb: def create @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.add_product(product.id) respond_to do

Ruby on Rails Country/State Select Enigma

好久不见. 提交于 2019-11-30 09:47:54
I am trying to implement something seemingly very simple, and I have been beating my head against it for days at this point. My desired end result is a Country select drop-down, tied to a State select drop-down, in such a way that when a given country is selected, IF states are known THEN those states are displayed in a select drop down, and if NO states are known for that country, then a text field is displayed instead. I feel like I am almost there. At this point the interface will actually generate that list of states based on the persons' country, except it is refusing to update the drop

Ajax pop up box using Ruby on Rails

戏子无情 提交于 2019-11-29 22:22:02
问题 This is a pretty basic question but I can't find a good answer for it. I have a page in my Rails app where there are many objects that can be 'flagged'. Clicking the flag button should display a little box with a confirmation, little form, etc. The trouble is I can't figure out how to do this using RJS templates. I've been using page.insert_html but this requires an ID. In order to make this work I had to assign each thing that can be flagged a unique ID. This doesn't seem very clean and

Ruby on Rails Country/State Select Enigma

橙三吉。 提交于 2019-11-29 15:24:43
问题 I am trying to implement something seemingly very simple, and I have been beating my head against it for days at this point. My desired end result is a Country select drop-down, tied to a State select drop-down, in such a way that when a given country is selected, IF states are known THEN those states are displayed in a select drop down, and if NO states are known for that country, then a text field is displayed instead. I feel like I am almost there. At this point the interface will actually

Rails 3: Simple AJAXy Page updates?

北城以北 提交于 2019-11-28 20:46:03
I can't believe I've been looking four hours for this simple task, but I have. In Rails 2.3, I could replace one section of a page with this simple code: render :update do |page| page.replace_html "div_id", :partial => "new_content",... end In Rails 3, Ryan Bates has me writing entire new javascript functions, switching from Prototype (rails default) to jQuery, and otherwise not enjoying life. The other tutes are no more straightforward. What am I missing? How do we replace a <div> these days? Ed Jones Thanks, guys. The official answer seems to be that, yes, the team felt simple is the enemy

(Rails) What is “RJS”?

让人想犯罪 __ 提交于 2019-11-28 18:38:30
I've seen "RJS" and "RJS templates" mentioned in passing in blog posts and tutorials. I did a search, but I'm still unsure about it. Is it a technology specific to Rails, rather than a standard like JSON or YAML? I understand it's used for "generating JavaScript." Does it generate generic JS or Rails-specific JS requiring the Prototype and Scriptaculous libraries? This Railscast gives a nice example of using RJS to add and remove form fields dynamically without hitting the server with an ajax call. These RJS tips may also be helpful. RJS is a template (similar to an html.erb file) that

Javascript Include Tag Best Practice in a Rails Application

﹥>﹥吖頭↗ 提交于 2019-11-28 15:20:49
Say I need to call a javascript file in the <head> of an ERb template. My instinct is to do the usual: <head> <%= javascript_include_tag :defaults %> <!-- For example --> </head> in my application's layout. The problem of course becoming that these javascript files are loaded into every page in my application, regardless of whether or not they are needed for the page being viewed. So what I'm wondering is if there's a good way of loading a javascript into the the headers of, for example, all ERb templates found only in a specific directory. maurycy I would use content_for . For instance,