Route Error within Rails App - html

In the process of installing Elasticsearch (which works fine) the ability to log out of my app isn't working anymore. I get the following error message.
No route matches [GET] "/users/sign_out"
Rails.root: C:/Users/mdavis/workspace/intakelog
Application Trace | Framework Trace | Full Trace
Routes match in priority from top to bottom
When I run Rake Routes, I see the correct path.
$ rake routes
Prefix Verb URI Pattern C ontroller#Action
insurances GET /insurances(.:format) i nsurances#index
POST /insurances(.:format) i nsurances#create
new_insurance GET /insurances/new(.:format) i nsurances#new
edit_insurance GET /insurances/:id/edit(.:format) i nsurances#edit
insurance GET /insurances/:id(.:format) i nsurances#show
PATCH /insurances/:id(.:format) i nsurances#update
PUT /insurances/:id(.:format) i nsurances#update
DELETE /insurances/:id(.:format) i nsurances#destroy
new_user_session GET /users/sign_in(.:format) d evise/sessions#new
user_session POST /users/sign_in(.:format) d evise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) d evise/sessions#destroy
user_password POST /users/password(.:format) d evise/passwords#create
new_user_password GET /users/password/new(.:format) d evise/passwords#new
edit_user_password GET /users/password/edit(.:format) d evise/passwords#edit
PATCH /users/password(.:format) d evise/passwords#update
PUT /users/password(.:format) d evise/passwords#update
cancel_user_registration GET /users/cancel(.:format) d evise/registrations#cancel
user_registration POST /users(.:format) d evise/registrations#create
new_user_registration GET /users/sign_up(.:format) d evise/registrations#new
edit_user_registration GET /users/edit(.:format) d evise/registrations#edit
PATCH /users(.:format) d evise/registrations#update
PUT /users(.:format) d evise/registrations#update
DELETE /users(.:format) d evise/registrations#destroy
search_accounts GET /accounts/search(.:format) a ccounts#search
account_notes POST /accounts/:account_id/notes(.:format) n otes#create
new_account_note GET /accounts/:account_id/notes/new(.:format) n otes#new
edit_account_note GET /accounts/:account_id/notes/:id/edit(.:format) n otes#edit
account_note PATCH /accounts/:account_id/notes/:id(.:format) n otes#update
PUT /accounts/:account_id/notes/:id(.:format) n otes#update
DELETE /accounts/:account_id/notes/:id(.:format) n otes#destroy
accounts GET /accounts(.:format) a ccounts#index
POST /accounts(.:format) a ccounts#create
new_account GET /accounts/new(.:format) a ccounts#new
edit_account GET /accounts/:id/edit(.:format) a ccounts#edit
account GET /accounts/:id(.:format) a ccounts#show
PATCH /accounts/:id(.:format) a ccounts#update
PUT /accounts/:id(.:format) a ccounts#update
DELETE /accounts/:id(.:format) a ccounts#destroy
programs GET /programs(.:format) p rograms#index
POST /programs(.:format) p rograms#create
new_program GET /programs/new(.:format) p rograms#new
edit_program GET /programs/:id/edit(.:format) p rograms#edit
program GET /programs/:id(.:format) p rograms#show
PATCH /programs/:id(.:format) p rograms#update
PUT /programs/:id(.:format) p rograms#update
DELETE /programs/:id(.:format) p rograms#destroy
pages_index GET /pages/index(.:format) p ages#index
root GET / p ages#index
This is the error message for the server logs
ActionController::RoutingError (No route matches [GET] "/javascripts/default.js"):
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.8) lib/rails/engine.rb:514:in `call'
railties (4.1.8) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (56.0ms)
Started GET "/users/sign_out" for 127.0.0.1 at 2015-11-13 11:43:11 -0500
ActionController::RoutingError (No route matches [GET] "/users/sign_out"):
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.8) lib/rails/engine.rb:514:in `call'
railties (4.1.8) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
I looked at the following post thinking it might be related but, I can't figure this out.
Rails ExecJS::ProgramError in Pages#home?
Copy of application.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= render 'layouts/bootstrap' %>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/bootstrap' %>
</head>
<body>
<div class="container">
<%= render "layouts/navbar" %>
</div>
<div class="container-fluid">
<div class="container">
<% flash.each do |name, msg| %>
<% if msg.is_a?(String) %>
<div class="alert alert-<%= name == "notice" ? "success" : "danger" %> alert-dismissable">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
</div>
</div>
</div>
<% end %>
<% end %>
<%= yield %>
<div class="container">
<div class="footer">
<%= render "layouts/footer" %>
</div>
</div>
</body>
</html>

If you have a default.js it might be that your application wants to precompile it first.
If so you have to set it in your config/initializers/assets
Rails.application.config.assets.precompile += %w( default.js )

The request method for the route missing message is [GET]:
No route matches [GET] "/users/sign_out"
But the route definition you have only accepts the DELETE method:
destroy_user_session DELETE /users/sign_out(.:format)
new_user_session GET /users/sign_in(.:format)
user_session POST /users/sign_in(.:format)
destroy_user_session DELETE /users/sign_out(.:format)
So making a GET request to that url is an invalid route.

The solution to this problem was that <%= javascript_include_tag 'application' %> wasn't stated in the application.html.erb file correctly. I needed to simplify the <%= javascript_include_tag "default", "data-turbolinks-track" => true %>. I'm not sure why I needed to change it in order for it to work.

Related

Jekyll-admin fails with NoMethodError - undefined method `config_files'

Using Mac M1 OS Big Sur 11.5.2
home-brew installed ruby 3.1.0, Jekyll 4.2.1
Git repo at https://github.com/amitaskitchen/amitaskitchen.github.io
When I add jekyll-admin to Gemfile... bundle exec jekyll serve comes up fine, but when I go to http://127.0.0.1:4000/admin - I see the error:
NoMethodError - undefined method `config_files'
Google'd the error and tried a bunch of things... but could not get rid of the error.
Any help / pointers would be appreciated.
Here is the complete error:
Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
Require just the needed backports instead, or 'backports/latest'.
Configuration file: /Users/agautam/workspace/amitaskitchen.github.io/_config.yml
Theme Config file: /usr/local/lib/ruby/gems/3.1.0/gems/popfolio-0.1.0/_config.yml
Source: /Users/agautam/workspace/amitaskitchen.github.io
Destination: /Users/agautam/workspace/amitaskitchen.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
done in 0.211 seconds.
Auto-regeneration: enabled for '/Users/agautam/workspace/amitaskitchen.github.io'
JekyllAdmin mode: production
Server address: http://127.0.0.1:4000/
Server running... press ctrl-c to stop.
2022-02-26 14:53:34 - NoMethodError - undefined method `config_files' for {"author"=>{"name"=>"Matt Shultz", "email"=>"matt#shultz.dev"}, "social"=>{"name"=>"David Darnes", "links"=>{"github"=>"popshift", "linkedin"=>"matt-shultz-85605ba6"}}, "lang"=>"en-US", "title"=>"Amitas Kitchen", "header_title"=>"PF", "css_inline"=>false, "avatar"=>"assets/avatar.png", "intro"=>{"main"=>"Hi, my name is Popshift", "sub"=>"I made this theme for you"}, "footer_message"=>"#coolhashtag 👍", "skills"=>[{"skill"=>"Javascript", "svg_id"=>"js-square"}, {"skill"=>"HTML", "svg_id"=>"html5"}, {"skill"=>"CSS", "svg_id"=>"css3-alt"}, {"skill"=>"React", "svg_id"=>"react"}, {"skill"=>"Python", "svg_id"=>"python"}, {"skill"=>"Node.JS", "svg_id"=>"node-js"}], "projects"=>[{"title"=>"Project 1 Title", "description"=>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", "url"=>"#", "image"=>"https://via.placeholder.com/250x200", "featured"=>true, "tags"=>["html", "css", "javascript"]}, {"title"=>"Project 2 Title", "description"=>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", "url"=>"#", "image"=>"https://via.placeholder.com/250x200", "featured"=>true, "tags"=>["html", "css", "javascript"]}, {"title"=>"Project 3 Title", "description"=>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", "url"=>"#", "image"=>"https://via.placeholder.com/250x200", "featured"=>true, "tags"=>["html", "css", "javascript"]}], "source"=>"/Users/agautam/workspace/amitaskitchen.github.io/", "destination"=>"/Users/agautam/workspace/amitaskitchen.github.io/_site", "collections_dir"=>"", "cache_dir"=>".jekyll-cache", "plugins_dir"=>"_plugins", "layouts_dir"=>"_layouts", "data_dir"=>"_data", "includes_dir"=>"_includes", "collections"=>{"posts"=>{"output"=>true, "permalink"=>"/:categories/:year/:month/:day/:title:output_ext"}}, "safe"=>false, "include"=>[".htaccess"], "exclude"=>[".sass-cache", ".jekyll-cache", "gemfiles", "Gemfile", "Gemfile.lock", "node_modules", "vendor/bundle/", "vendor/cache/", "vendor/gems/", "vendor/ruby/"], "keep_files"=>[".git", ".svn"], "encoding"=>"utf-8", "markdown_ext"=>"markdown,mkdown,mkdn,mkd,md", "strict_front_matter"=>false, "show_drafts"=>nil, "limit_posts"=>0, "future"=>false, "unpublished"=>false, "whitelist"=>[], "plugins"=>["jekyll-feed", "jekyll-admin"], "markdown"=>"kramdown", "highlighter"=>"rouge", "lsi"=>false, "excerpt_separator"=>"\n\n", "incremental"=>false, "detach"=>false, "port"=>"4000", "host"=>"127.0.0.1", "baseurl"=>"", "show_dir_listing"=>false, "permalink"=>"date", "paginate_path"=>"/page:num", "timezone"=>nil, "quiet"=>false, "verbose"=>false, "defaults"=>[], "liquid"=>{"error_mode"=>"warn", "strict_filters"=>false, "strict_variables"=>false}, "kramdown"=>{"auto_ids"=>true, "toc_levels"=>[1, 2, 3, 4, 5, 6], "entity_output"=>"as_char", "smart_quotes"=>"lsquo,rsquo,ldquo,rdquo", "input"=>"GFM", "hard_wrap"=>false, "guess_lang"=>true, "footnote_nr"=>1, "show_warnings"=>false, "syntax_highlighter"=>"rouge", "syntax_highlighter_opts"=>{"default_lang"=>"plaintext", "guess_lang"=>true}, "coderay"=>{}}, "email"=>"your-email#example.com", "description"=>"Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.", "url"=>"http://localhost:4000", "theme"=>"popfolio", "jekyll_admin"=>{"hidden_links"=>["configuration"]}, "livereload_port"=>35729, "serving"=>true, "watch"=>true}:Hash
sanitized_path configuration.config_files(overrides).first
^^^^^^^^^^^^^:
/usr/local/lib/ruby/gems/3.1.0/gems/jekyll-admin-0.11.0/lib/jekyll-admin/server/configuration.rb:47:in `configuration_path'
/usr/local/lib/ruby/gems/3.1.0/gems/jekyll-admin-0.11.0/lib/jekyll-admin/server/configuration.rb:34:in `parsed_configuration'
/usr/local/lib/ruby/gems/3.1.0/gems/jekyll-admin-0.11.0/lib/jekyll-admin/server/configuration.rb:8:in `block (2 levels) in <class:Server>'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `block in compile!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:994:in `route_eval'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015:in `block in process_route'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `catch'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `process_route'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:973:in `block in route!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `each'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `route!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085:in `block in dispatch!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082:in `dispatch!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `block in call!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `call!'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/xss_header.rb:18:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/path_traversal.rb:16:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/json_csrf.rb:18:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/base.rb:49:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/base.rb:49:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-protection-1.5.5/lib/rack/protection/frame_options.rb:31:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-1.6.13/lib/rack/nulllogger.rb:9:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-1.6.13/lib/rack/head.rb:13:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1787:in `synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call'
/usr/local/lib/ruby/gems/3.1.0/gems/rack-1.6.13/lib/rack/handler/webrick.rb:88:in `service'
/usr/local/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/httpserver.rb:140:in `service'
/usr/local/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/httpserver.rb:96:in `run'
/usr/local/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/server.rb:310:in `block in start_thread'
Thanks in advance.
The issue is caused by the presence of a config file in the theme-gem you're using.
Therefore instruct Jekyll to ignore the theme-config by adding the following to your config file:
ignore_theme_config: true

Passing parameters between nested includes

I want to be able to pass parameters from one include to another. However, Jekyll doesn't seem to like this.
index.md
{% include test-wrapper.html test-var='Foo' %}
test-wrapper.html
{% include test.html test-var={{ include.test-var }} %}
test.html
Got {{ test-var }}
Terminal output
$ bundle exec jekyll build --incremental --trace
Configuration file: /Path/to/project/_config.yml
Source: /Path/to/project
Destination: /Path/to/project/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: test.html test-var=Foo Valid syntax: {% include file.ext param='value' param2='value' %} in index.md
bundler: failed to load command: jekyll (/usr/local/bin/jekyll)
ArgumentError: Invalid syntax for include tag. File contains invalid characters or sequences:
test.html test-var=Foo
Valid syntax:
{% include file.ext param='value' param2='value' %}
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:67:in `validate_file_name'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:128:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:140:in `block in render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/context.rb:123:in `stack'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:137:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
/Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:126:in `render_liquid'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:79:in `render_document'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:62:in `run'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:479:in `render_regenerated'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:472:in `block in render_pages'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:471:in `each'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:471:in `render_pages'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:192:in `render'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:71:in `process'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/command.rb:28:in `process_site'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:65:in `build'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:36:in `process'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
/Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
/Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
/Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
/Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
/Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
/Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/exe/jekyll:15:in `<top (required)>'
/usr/local/bin/jekyll:22:in `load'
/usr/local/bin/jekyll:22:in `<top (required)>'
test-wrapper.html
{% include test.html test-var=include.test-var %}
test.html
Got {{ include.test-var }}

How i can minify the HTML output in ruby on rails?

I have a ruby on rails app, and i'm using HAML for HTML structure,
I'd like to minify/uglify the output "html", remove unnecessary whitespaces and new lines.
Something like this:
<div class='wrapper v2-header-wrapper' id='fix-content'><div class='header header-search' style='text-align: center !important;'><nav class='navbar navbar-toggleable-md navbar-light bg-faded navbar-expand-lg'><button class='navbar-toggler navbar-toggler-right' onclick='openNav()' type='button'><span class='navbar-toggler-icon'><i class='fa fa-bars'></i></span></button><a class='navbar-brand mobile pull-left' href='/'><i class='fa fa-search'></i>
Instead of this:
<div class='wrapper v2-header-wrapper' id='fix-content'>
<div class='header header-search' style='text-align: center !important;'>
<nav class='navbar navbar-toggleable-md navbar-light bg-faded navbar-expand-
lg'>
<button class='navbar-toggler navbar-toggler-right' onclick='openNav()'
type='button'>
<span class='navbar-toggler-icon'>
<i class='fa fa-bars'></i>
</span>
</button>
<a class='navbar-brand mobile pull-left' href='/'>
<i class='fa fa-search'></i>
Your help is highly appreciated, thanks in advance.
Have a go at this:
app/middleware/html_minifier.rb
class HtmlMinifier
def initialize(app)
#app = app
end
def call(env)
# Call the underlying application, return a standard Rack response
status, headers, response = #app.call(env)
# Make sure we don't process CSS or JavaScript
if headers["Content-Type"] =~ /text\/html/
response.each do |chunk|
[
# Join lines
[/[\r\n]+/, ""],
# Remove whitespace between tags
[/>\s+</, "><"],
# Remove comments
[/<!--(.|\s)*?-->/, ""],
# Remove whitespace in inline JavaScript
[/;\s+/, ";"],
[/{\s+/, "{"]
].each do |regex, substitute|
chunk.gsub! regex, substitute
end
end
end
# Return the new Rack response
[status, headers, response]
end
end
There is a Gem for that. Just add this to your Gemfile:
gem 'htmlcompressor', '~> 0.4.0'
And this to your application.rb:
config.middleware.use HtmlCompressor::Rack
I'm using that within a Rails 6 application and it worked out of the box.
I would also recommend to enable GZip compression. You can do that with this middleware:
config.middleware.use Rack::Deflater
No external Gem needed for the last middleware.

File Upload using Selenium Webdriver and ruby with < button type="button">

I am using Selenium WebDriver and Ruby and I need to automate the file upload feature.
I tried with
WAIT.until { driver.find_element(:css,'div.ui-dialog-buttonset').displayed? }
by using this it gives time out error
elem = driver.find_element(:css,'div.ui-dialog-buttonset')
puts "Hi"
js = <<-end
var buttons = document.querySelectorAll('button');
buttons[0].setAttribute('aria-disabled', true);
end
elem = driver.execute_script(js, elem)
puts elem
elem.send_keys("C:\\Users\\seema\\Desktop\\1413.jpg")
Above code is not working and script fails by following error
here is HTML code
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="otherButtonClass ui-state-hover ui-state-focus" type="button" role="button" aria-disabled="false">
<button class="otherButtonClass" type="button" role="button" aria-disabled="false" style="display: none;">
<button class="cancelButtonClass" type="button" role="button" aria-disabled="false">
</div>
</div>
here is error stack
,"message":"error - undefined me
thod `send_keys' for nil:NilClass \n [\"tests/upload_branding.rb:38:in `create_publish_pla
yer'\", \"tests/upload_branding.rb:80:in `PublishPlayerTest'\", \"org/jruby/RubyBasicObjec
t.java:1703:in `__send__'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest-4.7.4/lib
/minitest/unit.rb:1258:in `run'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest-rep
orters-0.14.20/lib/minitest/reporters.rb:62:in `run_with_hooks'\", \"c:/jruby-1.7.4/lib/ru
by/gems/shared/gems/scope-0.2.4/lib/scope.rb:105:in `run'\", \"org/jruby/RubyProc.java:255
:in `call'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/scope-0.2.4/lib/scope.rb:153:in `
recursively_run_setup_and_teardown'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/scope-0.
2.4/lib/scope.rb:155:in `recursively_run_setup_and_teardown'\", \"c:/jruby-1.7.4/lib/ruby/
gems/shared/gems/scope-0.2.4/lib/scope.rb:139:in `run_setup_and_teardown'\", \"c:/jruby-1.
7.4/lib/ruby/gems/shared/gems/scope-0.2.4/lib/scope.rb:105:in `run'\", \"c:/jruby-1.7.4/li
b/ruby/gems/shared/gems/minitest-4.7.4/lib/minitest/unit.rb:933:in `_run_suite'\", \"org/j
ruby/RubyArray.java:2417:in `map'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest-4
.7.4/lib/minitest/unit.rb:926:in `_run_suite'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gem
s/minitest-reporters-0.14.20/lib/minitest/reporter_runner.rb:45:in `_run_suite'\", \"c:/jr
uby-1.7.4/lib/ruby/gems/shared/gems/minitest-4.7.4/lib/minitest/parallel_each.rb:71:in `_r
un_suites'\", \"org/jruby/RubyArray.java:2417:in `map'\", \"c:/jruby-1.7.4/lib/ruby/gems/s
hared/gems/minitest-4.7.4/lib/minitest/parallel_each.rb:70:in `_run_suites'\", \"c:/jruby-
1.7.4/lib/ruby/gems/shared/gems/minitest-reporters-0.14.20/lib/minitest/reporter_runner.rb
:37:in `_run_suites'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest-4.7.4/lib/mini
test/unit.rb:877:in `_run_anything'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest
-4.7.4/lib/minitest/unit.rb:1085:in `run_tests'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/g
ems/minitest-reporters-0.14.20/lib/minitest/reporter_runner.rb:30:in `run_tests'\", \"org/
jruby/RubyBasicObject.java:1703:in `__send__'\", \"org/jruby/RubyKernel.java:2209:in `send
'\", \"c:/jruby-1.7.4/lib/ruby/gems/shared/gems/minitest-4.7.4/lib/minitest/unit.rb:1072:i
n `_run'\", \"org/jruby/RubyArray.java:1617:in `each'\", \"c:/jruby-1.7.4/lib/ruby/gems/sh
ared/gems/minitest-4.7.4/lib/minitest/unit.rb:1071:in `_run'\", \"c:/jruby-1.7.4/lib/ruby/
gems/shared/gems/minitest-4.7.4/lib/minitest/unit.rb:1059:in `run'\", \"tests/upload_brand
ing.rb:87:in `(root)'\"]","result":false}
In IRB i found following errors
irb(main):038:0> Wait.until { $driver.find_element(:css,'div.ui-dialog-buttonse>button')[1].displayed? }
Selenium::WebDriver::Error::TimeOutError: timed out after 80 seconds (Unable to locate element: {"method":"css selector","selector":"div.ui-dialog-buttonse>button"})}
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/wait.rb:57:in `until'
from (irb):38:in `evaluate'
from org/jruby/RubyKernel.java:1093:in `eval'
from org/jruby/RubyKernel.java:1489:in `loop'
from org/jruby/RubyKernel.java:1254:in `catch'
from org/jruby/RubyKernel.java:1254:in `catch'
from C:\jruby-1.7.4\/bin/jirb_swing:53:in `(root)'
also for second command
irb(main):043:0> elem = $driver.find_element(:css,'div.ui-dialog-buttonse>button')[1]
Selenium::WebDriver::Error::NoSuchElementError: Unable to locate element: {"method":"css selector","selector":"div.ui-dialog-buttonse>button"}
from [remote server] file:///C:/Users/seema/AppData/Local/Temp/webdriver-profile20130704-2984-1wifg7r/extensions/fxdriver#googlecode.com/components/driver_component.js:8444:in `FirefoxDriver.prototype.findElementInternal_'
from [remote server] file:///C:/Users/seema/AppData/Local/Temp/webdriver-profile20130704-2984-1wifg7r/extensions/fxdriver#googlecode.com/components/driver_component.js:8453:in `FirefoxDriver.prototype.findElement'
from [remote server] file:///C:/Users/seema/AppData/Local/Temp/webdriver-profile20130704-2984-1wifg7r/extensions/fxdriver#googlecode.com/components/command_processor.js:10456:in `DelayedCommand.prototype.executeInternal_/h'
from [remote server] file:///C:/Users/seema/AppData/Local/Temp/webdriver-profile20130704-2984-1wifg7r/extensions/fxdriver#googlecode.com/components/command_processor.js:10461:in `DelayedCommand.prototype.executeInternal_'
from [remote server] file:///C:/Users/seema/AppData/Local/Temp/webdriver-profile20130704-2984-1wifg7r/extensions/fxdriver#googlecode.com/components/command_processor.js:10401:in `DelayedCommand.prototype.execute/<'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in `raw_execute'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in `execute'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:575:in `find_element_by'
from C:/jruby-1.7.4/lib/ruby/gems/shared/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/search_context.rb:42:in `find_element'
from (irb):43:in `evaluate'
from C:\jruby-1.7.4\/bin/jirb_swing:53:in `(root)'
Kindly help
First check out the link Selenium::WebDriver::Wait to avoid such time out error.
You can try the below code :
# implicit time out declarations
wait = Selenium::WebDriver::Wait.new(:timeout => 60)
# wait till the required button element being displayed
# Use the link : http://www.w3schools.com/cssref/css_selectors.asp
# for css selectors
wait.until { driver.find_element(:css,'div.ui-dialog-buttonse>button')[1].displayed? }
elem = driver.find_element(:css,'div.ui-dialog-buttonse>button')[1]
elem.sendKeys("C://path/To/File.jpg")
Update
Looking at the link aria-disabled attribute and your part html below, I am seeing aria-disabled is set as false :
<button class="otherButtonClass ui-state-hover ui-state-focus" type="button" role="button" aria-disabled="false">
That desired button element is disabled.
Now see the question : Does WebDriver support file uploads?
You can't interact with the native OS file browser dialog directly, but we do some magic so that if you call WebElement#sendKeys("/path/to/file") on a file upload element, it does the right thing. Make sure you don't WebElement#click() the file upload element, or the browser will probably hang.
Update
#implicit time out declarations
wait = Selenium::WebDriver::Wait.new(:timeout => 60)
#wait till the div element is being displayed
wait.until { driver.find_element(:css,'div.ui-dialog-buttonse').displayed? }
elem = driver.find_element(:css,'div.ui-dialog-buttonse')
js = <<-end
var buttons = document.querySelectorAll('button');
buttons[0].setAttribute('aria-disabled', true);
end
elem = driver.execute_script(js, elem)
elem.sendKeys("C://path//To//File.jpg")

How to click a button element in watir?

Can I write watir code to click this button element?
The onclick event has to be triggered.
<button onclick="wizardAction('start', 'Starte Upgrade')">
<table align="center" cellspacing="0">
<tbody>
<tr>
<td><img src="/static/images/stock/gtk-ok.png" align="left" height="16" width="16"></td>
<td nowrap="nowrap">Starte Upgrade</td>
</tr>
</tbody>
</table>
</button>
Edit:
I tried it this way:
ie.button(:onclick, /start/).click
But it seems onclick is not supported:
> ruby upgrade-module.rb
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:143:in `match?':
onclick is an unknown way of finding an <INPUT> element ((?-mix:start)) (Watir:
:Exception::MissingWayOfFindingObjectException)
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:126
:in `locate'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:124
:in `each'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:124
:in `locate'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:122
:in `catch'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:122
:in `locate'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:119
:in `each'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/locator.rb:119
:in `locate'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/container.rb:8
04:in `locate_input_element'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/input_elements
.rb:5:in `locate'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/element.rb:53:
in `assert_exists'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/element.rb:288
:in `enabled?'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/element.rb:60:
in `assert_enabled'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/element.rb:233
:in `click!'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/element.rb:219
:in `click'
from upgrade-module.rb:19
One of these could work (not tested):
browser.image(:src => /gtk-ok/).click
browser.cell(:text => "Starte Upgrade").click
browser.button(:index => 1).click # assumes that it is the first button on the page
browser.button(:xpath => "//button[#onclick='wizardAction(\'start\', \'Starte Upgrade\')']").click
More information:
http://wiki.openqa.org/display/WTR/Buttons
http://wiki.openqa.org/display/WTR/XPath
http://wiki.openqa.org/display/WTR/Tutorial
I've run into problems like this. If the onclick attribute is not supported, you can do something like this.
b.
buttons.
to_a.
select{|but| but.attribute_value(:onclick).match(/start/) }.
first.
click
This is just something I'm typing out from memory, so it might need some tweaking. But it allows you to match things that Watir doesn't necessarily support.
I think there's also some way to do XPath queries with Watir, you might want to look into that as well