Ruby on Rails - Railscasts PRO #136 jQuery & Ajax (revised)

Railscasts Reloaded · 43K views · 2014 · 14:56

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering Rails questions about submitting forms or updating page parts via Ajax without a full page reload.

Recommended by 4 people across 4 different months, 2015 to 2019.

What it is

A roughly 15 minute screencast from the Railscasts Reloaded channel, based on Ryan Bates's Railscasts PRO series, that revisits episode 136. It shows how to convert a traditional Rails app to use Ajax by adding remote options, JavaScript templates (js.erb) and a bit of jQuery.

What people said

Recommends Richard Peck · 2015-11 · Stack Overflow · on “rails form post action without changing path”

Since your question is quite broad, I'll have to answer as such: if this is even possible Yes it's possible. You'll have to use ajax [LINK] to send an asynchronous request to your server. Ajax ( A synchronous J avascript A nd X ml ) sends requests out of scope of typical HTTP; you can send/receive "hidden" data without reloading (this is what you want): [LINK] Don't worry - ajax is really simple once you understand it. There's a great Railscast about it here [this video] : [LINK] Implementation For you, you will just have to get your form to submit over ajax (javascript). There are two ways to do this: Standard JS (JQuery) Rails UJS (unobtrusive Javascript [LINK] ) Basically, javascript acts as a

Recommends Aniket Rao · 2017-01 · Stack Overflow · on “Filtering categories”

So here is one approach you can take to achieve this. You can send AJAX request every time you click on a Provider to fetch its associated categories and append it to your HTML using JQuery. The code is quite elaborate to paste here, hence I suggest you to go through this video to understand how it works and implement it in a way that works for you. Ryan Bates explains this concept very well in the below video. [this video]

Recommends Maayan Naveh · 2018-05 · Stack Overflow · on “Jquery + Ajax in rails app making submit button become invisible”

I'm following this tutorial [this video] to create new Collections on-screen. It seems to be working, except when I click on the Create collection form link, my form submit button becomes a tiny square, barely visible. Here's my new.js.erb view: $('#new_link').hide().after('<%= j render("form") %>') Here's my new.html.erb view: <% provide(:title, 'New collection') %> <% provide(:button_text, 'Create collection') %> <div class="container"> <h1>New collection</h1> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= render 'form' %> </div> </div> </div> Here's my form partial: <div id="form"> <%= form_for([@seller, @collection]) do |f| %> <%= render 'shared/error_messages', object: @collect

Recommends Amit Patel · 2019-05 · Stack Overflow · on “Would like my bookmark action to work and stay on same page not render a new page, unsure of the right link_to helpers”

You basically need to use AJAX. First checkout [this video] and [LINK] to get and idea how AJAX work which will help you out to what you want to achieve.

Cites Richard Peck · 2016-02 · Stack Overflow · on “How to search, display and edit results on same page using Rails 4.2.4?”

Is it a good idea to create separate controller actions(and views) for each search option? ] No. You need to read up about MVC (Model View Controller) [LINK] . Your "view" logic should be handled in your controllers, data logic handled by models & views used to output the data. User should be able to search by all these three attributes(selected from a dropdown list) This is confusing; I would class a "search" as a way for me type text into a searchbox (text field), and have the results appear somewhere. What you're suggesting is probably filtering . To give you an overall pattern, here's what I'd do: #config/routes.rb resources :cars #-> url.com/cars #app/controllers/cars_controller.rb clas

Cites Kris Chery · 2016-06 · Stack Overflow · on “How can I implement Javascript/ Jquery in rails 4.2.4 with ruby 2.2.3”

I am having an issue with the javascript. Here is what I am attempting to do based on a tutorial I found on youtube, here is the link. [this video] I am trying to do that exactly but on index page of this controller basically.

Cites Second Son · 2016-09 · Stack Overflow · on “How do I use devise sign in/up in a different view as a partial”

I have my landing page which should contain and login form and a sign up form. I have two buttons of course once the user clicks on one of them it will render the appropriate form. I saw something like that on railscast [this video] . [LINK] Update I had generated devise views now I want to link those views into my landing page as partials. So that the user will click nicely on the button instead of loading the whole page it will just render the appropriate form. I hope this makes sense. Thanks for the help. <div class="col-md-4 landing-btns"> <h2>Join us and support the ones in need with every call!</h2> <p>All your information will stay private.</p> <div class="row"> <div class="col-md-12 "> <%

Cites Lenocam · 2017-02 · Stack Overflow · on “How do I update on object from two different views?”

I have an image that has a shared categories parameter. Right now it's functioning just how I'd like when I create or edit that image within a modal. It uses several js.erb partials to call new, create, edit and update. I'd like to also have the ability to update the categories on the image show page by clicking a checkbox and have the update occur using ajax immediately without pushing a button. Most of this works for me too. If I click on the checkbox and press the button to update it does, going through the update action in the controller. My CoffeeScript is written that if put a check in one of the boxes and I have it set to console.log or alert("whatever") it will. What I need to do is

Cites Alexander Luna · 2017-04 · Stack Overflow · on “Ajax on Rails How to use Ajax append method for render HTML?”

A few things you should know and will have to learn as you go on: Rails links come with a built in function to send ajax requests like this: <%= link_to "My ajax request text", post_new(@post), remote: true %> The "remote: true" option sends an ajax request for that link for you to the specified path (in this case a new post). Your controller receives every request and responds by redirecting or rendering views which refreshes the page. But when you do an ajax request you don't want that. What you want is that your controller responds via Ajax too. Once again, Rails has a built in function to do that: def billpreview # write all your logic and set instance variables for the objects you want

Cites fabOnReact · 2017-11 · Stack Overflow · on “Rails: jquery autocomplete in a search form”

This is the form erb code <%= form_tag products_path, method: :get do %> <%= text_field_tag :search, params[:search], size: 30 %> <%= submit_tag "Search", name: nil %> for this element [LINK] Inspect that element with your developer tolls and check the id generated from the erb code <%= text_field_tag :search, params[:search], size: 30 %> This is just an example, I don't have your app. On chrome you simply use the shortcut CTRL + SHIFT + c and then click with the mouse on the element you want to inspect (in this case that input form) The developer toolbar pops up already selecting that div, you can also do right click and then inspect, with the mouse [LINK] I believe text_field_tag :search s