Ruby Javascript Generator Templates. Uses the file extension .rjs. Not related to r.js.
Questions tagged [rjs]
213 questions
61
votes
4 answers
Javascript Include Tag Best Practice in a Rails Application
Say I need to call a javascript file in the of an ERb template.
My instinct is to do the usual:
<%= javascript_include_tag :defaults %>
in my application's layout. The problem of course becoming that these…

btw
- 7,006
- 9
- 40
- 40
36
votes
3 answers
(Rails) What is "RJS"?
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…

Ethan
- 57,819
- 63
- 187
- 237
13
votes
6 answers
Rails 3: Simple AJAXy Page updates?
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…

Ed Jones
- 251
- 1
- 2
- 7
10
votes
2 answers
Hacking RJS behaviour in Rails 5
I have a old rails 2.x project that I have converted mostly over to rails 5.
One issue is some of my actions used RJS, so it looked like:
if request.xhr?
render :action => 'new_user' and return
end
The new_user.js.rjs looks something…

Blankman
- 259,732
- 324
- 769
- 1,199
9
votes
7 answers
Is RJS evil and why?
I heard a bunch of rails developer saying that RJS is evil. I've never used it since I always managed to do what I wanted using classic javascript or jquery so I didn't pay attention. Now I'm getting into some legacy code and there's RJS all over…

marcgg
- 65,020
- 52
- 178
- 231
9
votes
2 answers
Rails 3.2.2 not executing rjs
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…

Daniel Estrada
- 926
- 8
- 9
7
votes
7 answers
Passing multiple rails variables to javascript
I have some values in ruby (variables and objects / hash) that I want to pass on to javascript on the rendered page. Currently I use these methods to simply write the javascript of declaring the variables at the client end.
def declare_as_js_vars…

alik
- 3,820
- 9
- 41
- 55
6
votes
3 answers
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…

Joseph Weissman
- 5,697
- 5
- 46
- 75
6
votes
4 answers
Redirecting to a 500 page when an AJAX call fails in Ruby on Rails
I'm working with an application built in Ruby on Rails with very poor error handling right now. If a controller method is executed via ajax, and that method results in a 500 (or 404 or any other response) the 500.html page is rendered and returned…

Kyle Boon
- 5,213
- 6
- 39
- 50
6
votes
3 answers
Cannot render JavaScript from Rails controller
I want to display a modal window with an error message, when the user has entered something invalid in a form, but render another action if everything is OK. However, when I try to display the modal window with
render :js =>…

Hermine D.
- 1,119
- 3
- 14
- 19
5
votes
2 answers
Rails 3 and RJS
I use the rails 3.0.0.beta
Is there any new syntax to write RJS, here is an example
def remote_create
@photo = Photo.new(params[:photo])
respond_to do |format|
if @photo.save
# add @photo's thumbnail to last import tag
…

denisjacquemin
- 7,414
- 10
- 55
- 72
5
votes
1 answer
how to use page.replace_html in rails 4
Hi currently I am upgrading my project from rails 3.2 to rails 4. After upgrading to rails 4. page.replace_html method is not working property.
eg:
In controller if it encountered code like this,
render :update do |page|
page.replace_html …

kannathasan
- 565
- 7
- 21
5
votes
5 answers
RJS or Javascript?
I've used RJS in the past for RoR projects and felt terribly constrained by what it could do. However, using Javascript alone felt/feels ugly and hack-y. This is particularly true when writing Javascript that manipulates Rails automagically…

Ron Gejman
- 6,135
- 3
- 25
- 34
4
votes
3 answers
Reuse js.rjs files in Rails?
i have an .js.rjs file, that must be used in many places.
How can i reuse it ?
For example, in my .js.rjs file i need something like this:
page << ( render "widely_used_stuff" )
where "widely_used_stuff" is a widely_used_stuff.js.rjs file, that…

AntonAL
- 16,692
- 21
- 80
- 114
4
votes
2 answers
Rails 3: RJS vs JavaScript
I've recently started learning Ruby on Rails, based on RoR3 beta/RC. I had earlier been developing applications using other frameworks (like Django), where the JavaScript had been written completely on my own.
When developing application using RoR,…

mhaligowski
- 2,182
- 20
- 26