rjs

Using RJS to Replace Div

I currently have a link which when clicked calls a JavaScript function, which gathers some data and then uses ProtoType to submit a form... function myFunction(){ data = someobject.getData(); $('myform').request({ parameters: {data:data, id:id,}, onSuccess: function(transport) { document.location.reload(); ...

Ruby on Rails Country/State Select Enigma

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...

(Rails,Javascript) RJS "Can't find variable" error not providing detailed information.

Hi All, I'm having an issue with rails involving javascript. Basically, I have the following code: <ul id="all-points"> <%for point in Point.find(:all)%> <%domid = "point[all][#{point.id}]"%> <li class="available-point" id='<%=domid%>'> <span> <%= link_to_remote "ADD",:url => {:action => "add_point"}, :html ...

Why does my RJS stop working when I set options in form_remote_for?

I am running into a strange problem. I simply want to display a loading icon on the page when pressing a button. If my call to form_remote_for contains Ajax options then the RJS script does not work. This works ("loading" is hidden by the controller and RJS): View: <%=form_remote_for(:job, @job, {:url => {:action=>:create}}) do |f...

To implement Reddit's login feature in Rails, would I need to use RJS and remote_form_for?

A feature in Reddit that I like is the ajax login - you enter your username and password on the front page and you never leave the front page even if there is a login error. If your login succeeds, I think it simply does something like a flash[:message] onto the front page to say "login successful". If I wanted to do this in Rails, would...

Passing objects from Rails RJS to a javascript function call without quoting the values?

In a Ruby on Rails project I need to have a JavaScript function executed at the end of an Ajax call. My problem is that the values being passed into the JavaScript function being called with page.call are being wrapped up in quotes. Not too much of a problem if you're passing in strings but one of the values is a string representation of...

Accessing values of elements in RJS

In Ruby on Rails I am working with an inline RJS and trying to find out which select option was selected by accessing selectedIndex property. For some reason unable to get this to work. So, for example assigning / altering the selectedIndex property works great: page['model_author_id'].selectedIndex = 5 But reading it and doing a co...

How can I get rails to send javascript errors to the log, not alert?

I'm new to Rails. Javascript errors to an alert box injure my soul. Is there a way to send it to console.log() instead of alert()? ...

Ajax pop up box using Ruby on Rails

Hi, 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 usin...

How to reload partial pages in Rails using RJS ?

Hi Currently i am working on a rails project . where i have to reload a partial page . For example Create action def create # Some transaction to the database respond_to do |format| format.html {render :text => 'Add post' } format.js end end In my views posts/create.js.rjs i would like to reload the users/...

rails rjs replacement and swap values

I'm trying to figure out how to use RJS to swap between two fields... i know how to replace the values but I can't seem to figure out how to read it. Is it not possible to read values thru RJS? Only to replace? <%= link_to_function "Swap" do |page| #to_value = page[:currency_to].value page[:currency_from].value = to_value...

rails autocomplete question about removing extraneous info

I've got my autocomplete plugin working perfectly... except I have certain info that I want displayed in the autocomplete divs, but I don't want to end up when the user makes their selection. Ie... I have an auto complete for currencies... they can search by either currency code or country... as they search it displays both info along w...

render collection of partials as html in rails

I am using jQuery to do an ajax call to my controller, and everything is working perfectly, except I can't quite get the return value that I want. Let's say I have a collection of items, and I have the partial: /app/views/messages/_message.html.erb I am trying to render it as a big string of text/html like so: format.js { render_to_...

Updating an element with RJS

I have an 'Save' button on my application, which saves a record via AJAX once edited. That code is working lovely. I have discovered a little bug though. If I click the save button, eventually the code below is invoked: page.replace_html "status-#{@restriction.id}", "Saved." page.delay(2) do page.visual_effect :fade, "status-#{@restri...

link_to_remote in Rails renders incorrect URL when rendered from RJS

I have a partial for a "guest" object which renders a link to a destroy action like this: <%= link_to_remote "remove", :url => { :action => "destroy", :id => guest.id } %> When called from an ERB view it works fine, e.g. <div id="guests"> <%= render :partial => @event.guests %> That is, it renders something like: <a href="#"...

Enforcing DRY: shared code between rjs files

Hi! How do you enforce DRY when you have shared code amongst rjs files? I'm trying to avoid the duplicated code in this example: thanks! ...

DRYing up routes and javascript responses

Hi, I'm not sure if I'm missing a known design pattern, but I keep coming up against the following problem with RESTful routes Rails. In my example, I have a users controller that can respond in javascript (:js) format. The default response populates a page element with a list of the paginated users: # /app/controllers/users_controlle...

rails form_remote_tag and onselect submit...

I have a form_remote working perfectly for the form currency. The only change I want to make is the do away with submit button for a select box. So they just click the correct currency and it submits the ajax request. <%= collection_select(:currency, :set, Currency.find(:all, :conditions => 'primary_source = "ECB"'), :code, :pretty_na...

rails rjs modify style in the body to add margin

How can I use RJS to modify CSS elements on a page? I'm looking to do modify the margin of a div to add a "margin-top: 2.8em;" How can I access this with RJS or should i use something like page << "document.getElementById('super-wrap').style.margin-top='2.8em;';" Though this doesn't work. Thanks ...

Nested link_to_function / insert_html causes javascript errors

Im using a link_to_function / insert_html to insert a partial into the page. Everything works fine, until i add another link_to_function / insert_html into the partial that is being rendered into the page. All of a sudden the outer link_to_function link stops working and throws this error: "missing } after property list" [Break on ...