turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 428 forks source link

Partial render issue #620

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi, I'm trying to render a partial view after a remote form post (render :new, change: :my_id) but the custom render method of Turbolinks isn't called (version 3.0.0 from master). After the post, the XHR query result is my HTML view not wrapped by Turbolinks.replace().

Gemfile

gem "turbolinks", github: "rails/turbolinks", branch: "master"

application.js.erb

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require all-my-custom-scripts
//= require turbolinks

It's working if I put the custom turbolinks render method in my controller.

def render(*args, &block)
  render_options = args.extract_options!
  turbolinks, options = _extract_turbolinks_options!(render_options)
  turbolinks = (request.xhr? && options.size > 0) if turbolinks.nil?

  if turbolinks
    response.content_type = Mime[:js]
  end

  super(*args, render_options, &block)

  if turbolinks
    self.status = 200
    self.response_body = "Turbolinks.replace('#{view_context.j(response.body)}'#{_turbolinks_js_options(options)});"
  end

  self.response_body
end

Thanks for your help.

Thibaut commented 8 years ago

Hey

ghost commented 8 years ago

Hi Thibaut,

Render function isn't overrided in my code.

config.turbolinks.auto_include = true is set in my development.rb file.

$ bundler show | grep turbolinks                                                                    ‹ruby-2.2.3›
  * jquery-turbolinks (2.1.0 6f336f1)
  * turbolinks (3.0.0 83d4b3d)

Gemfile

source "https://rubygems.org"

ruby ENV["CUSTOM_RUBY_VERSION"] || "2.2.3"

# Bundle edge Rails instead: gem "rails", github: "rails/rails"
gem "rails", "~> 4.2.4"

# A set of Rails responders to dry up your application
gem "responders", "~> 2.0"

# Use PostgreSQL as the database for Active Record
gem "pg"

# Use SCSS for stylesheets
#gem "sass-rails", "~> 5.0"

# Integrate SassC-Ruby with Rails!
gem "sassc-rails"

# Use Uglifier as compressor for JavaScript assets
gem "uglifier", ">= 1.3.0"

# Use CoffeeScript for .js.coffee assets and views
gem "coffee-rails", "~> 4.1.0"

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem "therubyracer",  platforms: :ruby

# Use jquery as the JavaScript library
gem "jquery-rails"

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem "turbolinks", github: "rails/turbolinks", branch: "master"

# jQuery plugin for drop-in fix binded events problem caused by Turbolinks
gem "jquery-turbolinks", github: "kossnocorp/jquery.turbolinks", branch: "master"

# Page-specific javascript for Rails done right
gem "paloma"

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.0"

# bundle exec rake doc:rails generates the API under doc/api.
gem "sdoc", "~> 0.4.0", group: :doc

# Use ActiveModel has_secure_password
gem "bcrypt", "~> 3.1.10"

# Use Capistrano for deployment
#gem "capistrano-rails", group: :development

# Slim template engine
gem "slim", github: "slim-template/slim", branch: "master"

# SASS Bootstrap
gem "autoprefixer-rails"
gem "bootstrap-sass", "~> 3.3.5"

# Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
gem "simple_form"

# Kinder, gentler I/O for Ruby
gem "kgio"

# Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.
gem "rest-client"

# A Ruby interface for the wonderful e-mail newsletter application Sendy
gem "sendyr"

# Fetch and parse feeds as quickly as possible
gem "feedjira"

# HTML/XML parser
gem "nokogiri"

# Rails helper to generate navigation links with a selected class.
gem "nav_lynx"

# Quick and configurable canonical tag to use in Rails views.
gem "canonical-rails", github: 'jumph4x/canonical-rails'

# Enumerated attributes with I18n and ActiveRecord/Mongoid support
gem "enumerize"

# Database based asynchronous priority queue system
gem "delayed_job_active_record"

# A simple date validator for Rails.
gem "date_validator"

# This Gem adds useful methods to your Rails app to validate, display and save phone numbers. 
gem "phony_rails"

# Preflight for HTML email
gem "premailer-rails"

# Translate your rails app route to various languages
gem "route_translator"

# Search Engine Optimization (SEO) plugin for Ruby on Rails applications
gem "meta-tags"

# Time calculation with business / working hours
gem "working_hours", github: "Intrepidd/working_hours"

# ActiveModel email validator (mx, disposable, ...)
gem "email_check", github: "dapatil/email_check"

# The Ruby gem for querying Maxmind.com's GeoIP database
gem "geoip"

# kramdown is a fast, pure Ruby Markdown superset converter
gem "kramdown"

# Segment.com library
gem 'analytics-ruby', '~> 2.0.0', :require => 'segment/analytics'

group :development, :test do
  # A modern, concurrent web server for Ruby
  gem "puma"

  # Call "byebug" anywhere in the code to stop execution and get a debugger console
  gem "byebug"

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem "spring"

  # Quiet Assets turns off the Rails asset pipeline log
  gem "quiet_assets"

  # Better Errors replaces the standard Rails error page with a much better and more useful error page.
  gem "better_errors"
  gem "binding_of_caller"

  # Supporting gem for Rails Panel (Google Chrome extension for Rails development)
  gem "meta_request"

  # Rspec for tests
  gem "rspec-rails"

  # Guard for automate gem installations, livereload, rails server restarts, etc
  gem "guard-rails"
  gem "guard-bundler"
  gem "guard-rspec"
end

group :production do
  # A fast and robust web server and application server for Ruby, Python and Node.js
  gem "passenger"

  # Enable all Heroku platform features
  gem "rails_12factor"

  # Enable gzip compression on heroku, but don"t compress images.
  gem "heroku-deflater"

  # New relic monitoring
  gem "newrelic_rpm"
end
alecdotninja commented 8 years ago

Hello @christopherdupont,

After a small investigation, the source of the problem seems to be the way that the meta-tags gem is using alias_method_chain to extend render in lib/meta_tags/controller_helper.rb.

Would you verify this by trying my fork of meta-tags (`gem "meta-tags", github: 'anarchocurious/meta-tags')?

If that does indeed solve your problem, perhaps someone with a better understand of alias_method_chain can explain why this is an issue, and whether it should be corrected in turbolinks or meta-tags.

ghost commented 8 years ago

Hello anarchocurious,

Thanks for your investigation, indeed, after my tests too, the issue is with the "meta-tags" gem.

Now, I'm using jQuery UJS for updating some area in my page.

Thibaut commented 8 years ago

Thanks for the investigation @anarchocurious.

alias_method_chain is deprecated in Rails 5. This should be fixed in meta-tags, not Turbolinks.