rjs

updating a select box based on another (Ruby on Rails)

北城余情 提交于 2020-01-23 17:54:26
问题 I'm in need of a more complete example on how to update a select box based on the results of a second select box in Ruby on Rails. I asked about this already here. I've read through the feedback from that posting, but am not having any luck figuring this out, and I've been trying for hours. Anybody know of a better (and more complete) example? 回答1: This is generally handled in Javascript. I don't particularly enjoy coding Javascript, so what I do for this in my application is to use a form

Passing a form object to a partial rendered from an ajax request

爷,独闯天下 提交于 2020-01-16 18:57:58
问题 I have an event form with some nested attribute models. The additional models are rendered after a client is selected from a select box. An observer watches and calls a controller action which renders a partial containing the fields_for nested models. The issue I'm having is that I can't pass the event 'form' block to the newly rendered partial - at least I can't figure out how... The code below raises the error: "wrong number of arguments (0 for 1)". Any help or suggestions are appreciated.

RJS error “object doesn't support this property ” on element update

青春壹個敷衍的年華 提交于 2020-01-15 12:16:11
问题 I have the following code in the controller. I am populating a drop down box dynamically based on the selection from another drop down box. def update_releases project = Project.find(params[:project_id]) releases = project.releases puts "releases==#{releases}" render :update do |page| page.replace_html 'releases', :partial => 'releases', :object => releases end view code: -form_tag reports_path(report_type=1),:method => :get, :multipart => true ,:id => "filter" do %table.grid.full %tr %td

Using js.rjs to render inline content

懵懂的女人 提交于 2020-01-06 19:34:12
问题 I am trying to improve my knowledge of Rails. I was trying to use js.rjs in a simple code. Here's the view: <div style="background: #000080; font-weight: bold; margin-left: 30px"><p>This should Remain Same</p></div> <div id="noid"> <%=link_to 'Click',:action=>:say_when , :remote => true %> and I will look it up. </div> And here's the controller: class DemoController < ApplicationController def say_when respond_to do |format| format.js end end end And I have views/Say_when.js.rjs as follows:

Confused as to which Prototype helper to use

♀尐吖头ヾ 提交于 2019-12-24 00:28:12
问题 After reading http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html I just can't seem to find what I'm looking for. I have a simplistic model that deletes the oldest message after the list of messages reaches 24, the model is this simple: class Message < ActiveRecord::Base after_create :destroy_old_messages protected def destroy_old_messages messages = Message.all(:order => 'updated_at DESC') messages[24..-1].each {|p| p.destroy } if messages.size >= 24 end end There is a

resource to learn using RJS in Ruby On Rails

ⅰ亾dé卋堺 提交于 2019-12-23 02:42:06
问题 I try to learn RJS usage in Rails application but I could not find good resource on Web. There are some simple examples but not a vast tutorial that I need. Please suggest any if you know :) Thanks ... 回答1: Doing a Google search, these links seems useful: 16 RJS Resources and Tutorials for Rails Programmers Getting Started With RJS in Rails Rails RJS Demo (video) Rails 3 and RJS (stackoverflow answer) 来源: https://stackoverflow.com/questions/10949079/resource-to-learn-using-rjs-in-ruby-on

Rails 3: Simple AJAXy Page updates?

﹥>﹥吖頭↗ 提交于 2019-12-17 22:51:37
问题 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

(Rails) What is “RJS”?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 22:36:32
问题 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? 回答1: This Railscast gives a nice example of using RJS to add and remove form fields dynamically without hitting the server with an

How to implement this nested linked_to_function?

一笑奈何 提交于 2019-12-13 08:26:09
问题 In my view I want the user to be able to browse a catalog of products. The hierarchy is as following: Category Product AdditionalInfoForm In my main view I render a partial for the categories: #opContent = render :partial => 'op_main_categories' The op_main_categories partial is defined as following: - @controller.getPortalCategories.each do |c| = link_to_function "#{c.name}", :class => 'opCategoryHeaderText' do |page| - partial = escape_javascript(render :partial => 'op_secondary_categories'

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