DEVISE - No route matches [GET] "/users/sign_out" - Rails 4 - javascript

Nothing on the internet solved this problem.
I'm running on Rails 4.2.3 and Ruby 2.1.5
After an installation of devise, I got this error.
When I delete the line
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true % from my layout file, the error is gone and everyting looks fine.
I tried everything found on stackoverflow, didn't work.
Right now:
I use <%= link_to "sign out", destroy_user_session_path, method: :delete %> in my layout.
I tried to change the initializer : config.sign_out_via = :delete to "get" also, didn't work. Now remains "delete". Anyway it should be delete in my opinion.
My application.js file includes : //= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Routes.rb file includes devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}. If I don't add this line, it's not working also.
If I delete <%= javascript_include_tag 'application', 'data-turbolinks-track' => true % from my layout file it's working. If I don't, it's not working.
What is the problem with this javascript thing? Any opinion is welcome.

Try using the jquery-turbolinks gem and modify your application.js to look like this:
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require_tree .
//= require turbolinks

Ok the problem seems like because of Windows. The solution is adding the gemfile : 'coffee-script-source', '1.8.0' and bundle update coffee-script-source This solved.

Related

Rails_Javascript loads only if I pass by index home page

I am facing a javascript issue on Rails;
I used this web app in order to publish a book rating system
I've noticed that when I go to my homepage (index), then I click on the book that I want to rate (, the script loads and everything works fine, but when I go directly to the book without passing by the home page, the script of rating will not load
on application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
on the head of application.html.erb
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
What am I missing ?
It may be caused by turbolinks which uses AJAX to view templates to speed things up. But it will cause JavaScripts to not load without a page refresh. You can try removing the turbolinks gem from your gemfile and run bundle install. Alternatively you can wrap the raty javascript with the following. So put the first line at the beginning of your javascript and close your javascript with the last line.
$(document).on('turbolinks:load', function() {
...your jQuery/javascript goes here...
});

Rails Javascript onchange works with <script> but not externally

In my index.html.erb file I have a form that successfully submits onChange. However, this only works if I use <script> tags placed after my form. Why is the same js in welcome.js not running? Index loads as a /welcome route.
# app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ace.min
//= require jquery.sortable
//= require chartkick
//= require hammer
//= require_tree .
External js file
# app/assets/javascripts/welcome.js
$('.chart-radio-icon').change(function(){
$('#mega_form').submit();
});
View
# views/welcome/index.html.erb
<%= form_tag mega_chart_path, id: 'mega_form', remote: true do %>
<%= radio_button_tag :metric_type, :followers_count, true, :class => 'chart-radio-icon'%>
<%= label_tag(:followers, 'Followers', :class => 'chart-label chart-label-social') %>
Again, the js works when placed in <script> tags in the view, but not externally.
EDIT:
Since we've determined that your asset files are not being included in development. For a sanity check try this and restart your server:
Rails.application.config.assets.precompile = %w( application.js application.css )
END EDIT
Since you are using a require_tree ., and since the welcome.js file is in app/assets/javascripts, it will be included on all pages in your application. See here.
I think that the problem is that on page load, the event listener is not being assigned to the DOM element. Try wrapping your JS code in:
#app/assets/javascripts/welcome.js
$(document).ready(function(){
....
});

Rails 4.0.1 JavaScript Asset Pipeline - Cross Browser Support - Loading Issue

I am working on a rails 4.0.1 application.
I have a a set of interactive slides, intended to teach personal finance. I have a list of question and buttons that when clicked show a jQuery Modal popup window.
My javascript files aren't loading after I perform a <%= link_to %> the next slide with Safari and Mozilla. There is no issues with Chrome.
If I reload the page, the modal does magically start working again. Here is the files that I believe are related. Any help is greatly appreciated.
application.html.erb
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
routes.rb
match '/slide1', to: 'interest_rates#slide1', via: 'get'
match '/slide2', to: 'interest_rates#slide2', via: 'get'
match '/slide3', to: 'interest_rates#slide3', via: 'get'
match '/slide4', to: 'interest_rates#slide4', via: 'get'
match '/slide5', to: 'interest_rates#slide5', via: 'get'
match '/slide6', to: 'interest_rates#slide6', via: 'get'
application.js
//= require turbolinks
//= require jquery
//= require d3.v3
//= require d3.layout
//= require rickshaw
//= require custom
//= require graph
slide1.html.erb
<%= link_to "Next", {:controller => :interest_rates, :action => :slide2}, class: "button" %>
If you haven't already, maybe check out the jquery-turbolinks gem and therubyracer gem. I've had issues where javascript wasn't loading properly, and after using the jquery-turbolinks gem, everything worked.
In my gemfile:
gem "jquery-turbolinks", "~> 2.0.1"
gem 'therubyracer', :require => 'v8'

Client Side Validations and Rails4

I integrated client side validations with rails4 using the new branches available using the following gems
gem 'simple_form', '~> 3.0.0.rc'
gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta"
gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git'
gem "jquery-rails"
I also added the required JavaScript as the following
//= require jquery
//= require jquery_ujs
//= require foundation
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .
//= require_self
I created this test form in order to see if it works
= simple_form_for(#post, :validate => true) do |f|
= f.error_notification
.form-inputs
= f.input :title, :required => true
.form-actions
= f.button :submit
of course in the model, it was
validates :title, presence: true
The problem is I can't figure our why it is not working, while JavaScript Console shows the following error:
Uncaught TypeError: Cannot read property 'add' of undefined
These gems involve a lot of configurations and ordering to be proper. Instead of explaining the whole procedure i can give you a link in SO where a similar problem was solved. Please do check it out and follow the same.
ruby-on-rails client_side_validation simple_form javascript error
Hope it helped !
The problem appear to be in the order of the javascript, just change the order it will work fine

Unable to delete and display confirm box

I am unable to delete or display a confirm box in Rails 3.1.
I have the following lines in my application.hmtl.erb layout :
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
I have also tried to change "application" to :defaults or "prototype" or "jquery" but it didn't change anything.
Need help with this !
Confirm boxes and routing to REST actions are done by the the unobtrusive javascript file. You have this problem, because you don't have it included.
Check inside your application.js if you have the following lines (before any actual javascript code):
//= require jquery
//= require jquery_ujs
This example assumes that you have the jquery-rails gem in your Gemfile. If you have prototype-rails, you should switch to:
//= require prototype
//= require prototype_ujs

Categories

Resources