I tried to follow this tutorial by GoRails to add EasyAutoComplete to my Rails app:
https://www.youtube.com/watch?v=ibxlNN73UTY
Although the search bar functions as the GoRails guy demonstrates, I keep seeing this page whenever I click on any link:
If I refresh this page, then it takes me to the user sign in page that I originally clicked on. I don't notice anything out of the ordinary in my Rails server console throughout this process.
I added the css files and the js files for EasyAutoComplete to my Assets pipeline, because I was having a hard time using webpacker correctly.
For jquery, I followed this article to install it: https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker
and I used this video as reference as well:
https://www.youtube.com/watch?v=bn9arlhfaXc
My Gemfile looks like:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0.rc2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'redis'
gem 'braintree'
gem 'bcrypt'
gem 'foreman'
gem 'rails-controller-testing'
gem 'faker'
gem 'pagy'
gem 'figaro'
gem 'gon'
gem 'modernizr-rails'
gem 'stripe-rails'
# thirdparty authentications
gem 'omniauth-google-oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'activerecord-session_store'
# for front end
gem 'react-rails'
gem 'bootstrap'
gem 'sprockets-rails'
gem 'jquery-rails'
# catches test emails
gem 'mailcatcher'
gem 'devise'
# admin panel
gem 'rails_admin'
# active storage variant
gem 'mini_magick', '~> 4.8'
gem 'rack', '~> 2.0.8'
gem 'ransack'
My search.js looks like:
document.addEventListener('turbolinks:load', function () {
$input = $("[data-behavior='autocomplete']")
var options = {
getValue: 'name',
url: function (phrase) {
return '/search.json?q=' + phrase
},
categories: [
{
listLocation: 'products',
header: '<strong>Products</strong>'
}
],
list: {
onChooseEvent: function () {
var url = $input.getSelectedItemData().url
$input.val('')
Turbolinks.visit(url)
}
}
}
$input.easyAutocomplete(options)
})
My application.js in app/javascript/packs looks like:
require('#rails/ujs').start()
require('turbolinks').start()
require('#rails/activestorage').start()
require('channels')
require('jquery')
//= require jquery
//= require popper
//= require bootstrap-sprockets
//= require jquery.easy-autocomplete
Any help would be greatly appreciated!
Edit:
When I remove the "require('turbolinks').start()" in my application.js the problem goes away but my search bar stops working.
When I click on a link with my developer console up I see this:
I also created a sample app that also has the same problem in this repository:
https://github.com/zx1301/sampleAppTurbolinksError
I'm using ruby 2.6.2 and rails 6.0.2. In its current state I commented out the lines linking the css and js files to easyAutocomplete and the problem persists unless I disable turbolinks by commenting out turbolinks in application.js.
Going by where the links in the repo you linked navigate to (nowhere #), this is a known issue with turbolinks.
You can add data-turbolinks="false" to the link tags to prevent this type of behavior.
Related
Before a deployment, I ran bundle install and bundle update. Then my Rails version switched from 5.2.4 to 5.2.5, and several gems were upgraded too. Everything is still working perfectly in development environment.
But problems appeared after deploying to production environment. I have the following issue, which I think is related to assets. Any page I request, the following message ends up in the log file:
I, [2021-04-22T22:48:43.887632 #7620] INFO -- : Rendered users/index.html.erb within layouts/application (11.6ms)
I, [2021-04-22T22:48:44.149881 #7620] INFO -- : Completed 500 Internal Server Error in 294ms (ActiveRecord: 1.9ms)
F, [2021-04-22T22:48:44.150616 #7620] FATAL -- :
F, [2021-04-22T22:48:44.150738 #7620] FATAL -- : ActionView::Template::Error (application.css):
F, [2021-04-22T22:48:44.150992 #7620] FATAL -- :
9: <title><%= full_title(yield(:title)).html_safe %></title>
10:
11: <link href="/assets/oblique-4.1.1/styles/images/favicon.png" rel="shortcut icon">
12: <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
13: <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
14: <%= csrf_meta_tags %>
15: <%= render "layouts/shim" %>
F, [2021-04-22T22:48:44.151084 #7620] FATAL -- :
F, [2021-04-22T22:48:44.151184 #7620] FATAL -- : app/views/layouts/application.html.erb:12:in `_app_views_layouts_application_html_erb__255798539_93007000'
app/controllers/users_controller.rb:22:in `block (2 levels) in index'
app/controllers/users_controller.rb:21:in `index'
This happens only in the production environment, of which configurationis given by the untouched production.rb file:
DataQualityManager::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
# config.assets.debug = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(harmony: true)
# config.assets.css_compressor = :sass --> automatically used due to sass-rails gem
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
# config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Store uploaded files locally.
config.active_storage.service = :local
# Define connection to email services
config.action_mailer.default_url_options = { :host => 'l021000110029b.adr.admin.ch/' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
end
The Gemfile contains:
source 'https://rubygems.org'
gem 'rails', '~> 5.2'
gem 'bootstrap-sass'
gem 'sassc-rails'
gem 'coffee-rails', '~> 5.0'
gem 'uglifier', '~> 4.0'
gem 'bcrypt', '~> 3.1'
gem 'jquery-rails'
gem 'turbolinks', '~> 5.2'
gem 'jbuilder', '~> 2.6'
gem 'will_paginate', '~> 3.1'
gem 'd3-rails'
gem 'js_cookie_rails'
gem 'httparty', '~> 0.14'
gem 'nested_form_fields'
gem 'pg'
gem 'deep_cloneable', '~> 3.0'
#gem 'acts-as-taggable-on', '~> 6.0'
gem 'tzinfo-data'
gem 'audited', '~> 4.9'
gem 'awesome_print' # Layout enhancement for Audited
# Generate SQL scripts via renderer
gem 'sql_query'
# Workflow support
gem 'workflow-activerecord', '>= 4.1', '< 6.0'
# Full-text search with Postgres
gem 'pg_search'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# XLSX format support
gem 'write_xlsx'
gem 'write_xlsx_rails', git: 'https://github.com/fchampreux/write_xlsx_rails.git', branch: 'master'
gem 'roo'
# Authentication and Authorisations
gem 'devise'
gem 'devise-security'
gem 'email_address' # for email validation
gem 'cancancan', '~> 3.0'
# MarkDown parser
gem 'redcarpet', '~> 3.5'
# eMail notification support
gem 'mailgun-ruby', '~>1.1'
# gem for dev and test only
group :development, :test, :validation do
gem 'annotate', '~> 3.0'
gem 'byebug'
gem 'faker'
gem 'shoulda-matchers'
gem 'rails-controller-testing'
gem 'rspec-rails', '~> 4.0'
gem 'factory_bot_rails', '~> 6.0'
gem 'capybara', '~> 3.15'
gem 'database_cleaner-active_record'
gem 'selenium-webdriver', '~>3.140'
end
Can you help me understand what causes the failure after the upgrade?
Thanks a lot!
As a beginner on Rails 6. Whenever, i click on the Roar Link then it gives me the following error. The following files are attached below. I just want to add custom file(demo.js) into my code so that i can test the behavior of JavaScript in my following code. Java Script behavior on Rails 5 is different from the Rails 6.
Kindly give me the better solution so that i can solve my problem. I tried all of answers on stack overflow.
Application.html.erb (views/layouts/application.html.erb)
<!DOCTYPE html>
<html>
<head>
<title>SimpleCms</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
demo.js (app/javascript/packs/demo.js)
function jsRoar(name) {
alert('I am ' + name + '. Hear me roar!');
}
application.js (app/javascript/packs/application.js)
require("#rails/ujs").start()
require("turbolinks").start()
require("#rails/activestorage").start()
require("channels")
require("packs/demo")
index.html.erb (views/demo/index.html.erb)
<h1>This is the index Page</h1>
<br/>
<%= link_to('All Subjects',subjects_path) %>
<%= link_to('Roar', '#', :onclick => "jsRoar('JavaScript'); return true;") %>
demo_controller.rb
class DemoController < ApplicationController
layout 'application'
def index
render ('index')
end
def hello
render ('hello')
end
end
GEM File
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.6'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more:
https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
You're thinking of the old way of doing it. I've explained it here:
https://stackoverflow.com/a/56549843/1238868
Here's a more modern way of doing what you're trying.
<%= link_to('Roar', '#', data: {roar: 'JavaScript'}) %>
In demo.js:
document.addEventListener("turbolinks:load", function() {
document.querySelectorAll('[data-roar]').forEach(function(roaring_link) {
roaring_link.addEventListener('click', function(event) {
let name = roaring_link.dataset['roar']
alert('I am ' + name + '. Hear me roar!');
event.preventDefault();
event.stopPropagation();
return false;
});
});
});
Note that the code in demo.js is self-contained and simply looks at the document and attaches the desired functionality to the links. You specify what links those are by adding a data attribute with the data that you wish to pass to your javascript function.
This might seem complicated but after you get the hang of it you'll find your javascript is really clean and easy to maintain.
I'm deploying a rails app to Heroku, and the process runs smoothly but on running the app in a browser, javascripts and drop-downs do not work.
I thought the Turbolinks might be the problem but after i fixed it locally, it doesn't seem to reflect in Heroku.
i have tried restarting the app server on Heroku using
'heroku restart'
i tried precompiling the assets in development mode before deploying using
'heroku run rake assets:precompile -a rhino-base'
i tried inspecting elements using chrome>inspect>console but i only see 1 error yet ALL the js scripts don't work.
here is my GEM FILE
'source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.4.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1', '>= 5.2.1.1'
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
end
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 4.1.18'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'duktape'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
gem 'jquery-turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
##################################################
gem 'jquery-rails'
gem 'jquery-slimscroll-rails','~> 1.0','>= 1.0.9'
gem 'jquery-migrate-rails', '~> 1.2', '>= 1.2.1'
##################################################
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]'
heres my application.js FILE '
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.turbolinks
//= require rails-ujs
//= require activestorage
//= require_tree .
//= require turbolinks'
here is my production.rb FILE
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "rhinoBaseSite_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
I expected that since everything works in development and production, it should also work on deployment.
so anyone else with this problem, here is what worked for me. Not all javascript files play nice when compiled in a single space. Compile them separately.
in your
config/initializers/assets.rb file have this line for the specific script you would love to compile in a separate file
Rails.application.config.assets.precompile += %w( path-to-file-in-javascripts-folder/file-name.js path-to-file-in-stylesheet-folder/file-name.scss)
for example
Rails.application.config.assets.precompile += %w( plugins/fullcalendar/fullcalendar.js )
then update your application.js and remove
//= require tree
then update your app/views/layouts/application.html.erb file and add the precompile asset path adding the /assets before the location. Like this
<%= javascript_include_tag '/assets/plugins/datatables/export/pdfmake.min' %>
now put all the files you had precompiled inside of the public/assets folder. then push to heroku.
I am getting an error when I startup my local server rails s
Error message:
compile ((execjs):6633:19): SyntaxError: [stdin]:5:10: unexpected . (ExecJS::RuntimeError)
and line 6 in my application.html.erb is highlighted:
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'bootstrap-sass', '~> 3.3.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'therubyracer', '0.12.1'
gem 'execjs'
gem 'node', '~> 0.0.2'
gem 'react-rails', '~> 1.0'
# 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'
# 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.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
I am using react-rails gem to render my #records object.
in app/assets/javascripts/components/records.js.coffee
#records = React.createClass
render: ->
React.DOM.div
className: 'records'
React.DOM.h2
className: 'title'
'Records'
Anybody knows why I am getting this error message ?
I found the problem... CoffeeScript is very meticulous about spacing. I need to start the function with a one tab spacing like so:
#Records = React.createClass
render: ->
React.DOM.div
className: 'records'
React.DOM.h2
className: 'title'
'Records'
Also posted here: https://gist.github.com/1100596. (This problem does not pertain to the CoffeeBeans gem alone, I don't think.)
# Controller
class RestaurantsController < ApplicationController
def show
#restaurant = Restaurant.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.js # show.js.coffee
end
end
end
# restaurants/show.html.erb
<%= link_to "Breakfast", #restaurant, :remote => true, :id => "breakfast_filter" %>
# restaurants/show.js.coffee
alert("here we are");
Why is the show.js.coffee file never reached? In fact, even if it were show.js.erb, it wouldn't be reached...
The whole point is so I can reload part of the show.html.erb page with AJAX.
Background: I'm using Rails 3.1rc4, and my Gemfile is as follows:
source 'http://rubygems.org'
# Using ruby 1.9.2p180
gem 'rails', '3.1.0.rc4' # :git => 'git://github.com/rails/rails.git', :branch => '3-1-stable'
gem 'sprockets', '2.0.0.beta.10' # :git => 'git://github.com/sstephenson/sprockets.git'
#gem 'mysql2' # No longer MySQL
gem 'pg', '0.11.0' # For PostgreSQL db
gem 'authlogic', '3.0.3' # smart user authentication
gem 'cancan', '1.6.5' # manage abilities across types of users
gem 'dynamic_form', '1.1.4' # easy error messages for forms
# Asset template engines
gem 'sass-rails', '~> 3.1.0.rc'
gem 'coffee-script', '~> 2.2.0'
gem 'uglifier', '~> 1.0.0' # compresses JS code for production
# We use jQuery, the default
gem 'jquery-rails', '>= 1.0.12'
# Temporary - 3.1 SHOULD require >=0.9.2, but there are still bugs
gem 'rake', '0.8.7'
# This makes AJAX and CoffeeScript play nicely together
gem 'coffeebeans'
group :production do
gem 'therubyracer', '~> 0.9.3.beta1'
end
gem 'factory_girl_rails' # seeds.rb needs this
#gem 'forgery'
group :test, :development do
# helpers
gem 'database_cleaner'
# core testing frameworks
gem 'rspec-rails', '>= 2.6.1'
gem 'cucumber-rails', '>= 1.0.0'
gem 'capybara', '>= 1.0.0'
# Pretty printed test output
gem 'turn', :require => false
end
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
Help appreciated.