NameError in Spree::Products#show - ruby

This code used to work on rails 3.2.13 and spree 2.0, now with rails 4.0 and spree 2.1 raises the following error.
Showing /var/lib/gems/1.9.1/gems/spree_frontend-2.1.1/app/views/spree/products/show.html.erb where line #19 raised:
undefined local variable or method `active_record' for #<ActiveRecord::Associations::JoinDependency::JoinAssociation:0xb3187c8>
Extracted source (around line #19):
<% Spree::PROPERTIES_LEFT.each do |show_type| %>
<% unless #product_properties.hash_for(show_type).empty? %>
<% for title in #product_properties.hash_for(show_type).keys %>
<h6 class="product-section-title"><%= title %></h6>
Rails.root: /home/anakin/SpreeTravelData/openjaf/spree_travel_demo
The line 19 is:
<% unless #product_properties.hash_for(show_type).empty? %>
How can I fix this ?

I think you should try to clean up your environment and make a clean bundle install and bundle update when you work with rails offline, it gets tricky to get a hold on all the dependencies. I had this exact problem and that's the way to go. Sadly is go online or go crazy.

Related

Rails 6.1.1 doesn't load the webpacker created CSS files in production mode

this is my first time asking a question here, I hope I would explain my problem well.
In one of my recent tasks, I'm upgrading our app to Ruby and Rails (Ruby 2.6.6 > 2.7.2, Rails 6.0.3.2. > 6.1.1)
I had several issues along the way, upgraded some gems and JS libraries. The application runs fine in development mode. However when I switch to production mode, I run these commands to compile and run the server.
RAILS_ENV=production bundle exec rake webpacker:compile
./node_modules/webpack/bin/webpack.js --config webpack.config.js
When I run the app, in production mode it looks running normal, but when I go to localhost:3000 it throws several 500 errors regarding to CSS files. I see the main page of the app as plain HTML, without CSS.
2021-01-22 11:50:51 -0500 Rack app ("GET /assets/stylesheets/app-styles-3661efb317da3fb28f52.css" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/landing.debug-05588bd014e46c264aaf6e00d2f5c570dd7ca3ed42336c2ff6d5c05bf986afe2.js" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/companyLogo-6700adf796812269b9428251803c253b9c073095ef511d3619d269a0fdd96435.png" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
Files which are mentioned in the error are exists under the /public folder. In the browser's page source, I can see the path as well. When I click the folder path on page source, I see this error on the browser.
An unhandled lowlevel error occurred. The application logs may have details.
When I check the docs of RoR, the match? method for ActionDispatch::FileHandler is not there, but in 6.0.3.2 docs, it is deprecated without a notice, maybe.?. It is not something I call intentionally, it is probably called somewhere in Rails when the app is running on production mode.
I have those helper in my erb files.
<%= javascript_pack_tag 'application' %>
<%= stylesheet_pack_tag 'application' %>
I tried replacing them with
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
but no luck :(
I tried this as well.
Is anyone have an idea how can I make sure Rails is loading these files and accessible in the user side? Or any better debugging suggestions are appreciated!
Thanks in advance!
Note: When I switch to development mode, everything works fine.
BTW, Some Packages I use:
"#rails/webpacker": "5.2.1" #-> was 4.0.2
"webpack-bundle-analyzer": "3.3.2"
"webpack-manifest-plugin": "3.0.0-rc.0" #-> was 2.0.4
"webpack-cli": "4.4.0", #-> was 3.3.0 and it was only devDependency
We had the same issue with the match? method missing for ActionDispatch::FileHandler
We traced it back to: https://github.com/romanbsd/heroku-deflater/issues/54
Removing the heroku-deflater gem fixed it for us
If you have issues with this and get a error like this:
ActionView::Template::Error (Webpacker can't find application.css in /webapp/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
"application.js": "/packs/js/application-26b24ac7b08f8a1b640f.js",
"application.js.map": "/packs/js/application-26b24ac7b08f8a1b640f.js.map",
"entrypoints": {
"application": {
"js": [
"/packs/js/application-26b24ac7b08f8a1b640f.js"
],
"js.map": [
"/packs/js/application-26b24ac7b08f8a1b640f.js.map"
]
},
}
):
You can resolve it by deleting the stylesheet_pack_tag in app/views/layouts/application.html.erb. The javascript_pack_tag directive loads the scss/css.
You can see in the error message entrypoints that the scss was not generated, its inside the js. I've self inflicted this error on me because of outdated guides.
Example
With the following files & contents:
app/javascript/packs/application.js
// rails generated stuff
import "styles/application.scss"
app/javascript/styles/application.scss
// some scss rules
body { background-color: red; }
app/views/layouts/application.html.erb:
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

Redmine error after migrating to new version

I wanted to migrate from old Redmine version 3.1 to latest one. I installed redmine with plugins which I use, everything worked.
Then I imported database from old Redmine version, but when I click on task, od project, I am geting this error.
Since I am not Ruby programmer, wanted to ask what this means and if there is possibility to fix?
Rendered projects/show.html.erb within layouts/base (7.6ms)
Completed 500 Internal Server Error in 153ms (ActiveRecord: 114.7ms)
ActionView::Template::Error (undefined method `description' for #<Tracker:0x00000000076ad540>):
65: <% #trackers.each do |tracker| %>
66: <tr>
67: <td class="name">
68: <%= link_to tracker.name, project_issues_path(#project, :set_filter => 1, :tracker_id => tracker.id), :title => tracker.description %>
69: </td>
70: <td>
71: <%= link_to #open_issues_by_tracker[tracker].to_i, project_issues_path(#project, :set_filter => 1, :tracker_id => tracker.id) %>
app/views/projects/show.html.erb:68:in `block in _app_views_projects_show_html_erb__4349052137991159230_63703440'
app/views/projects/show.html.erb:65:in `_app_views_projects_show_html_erb__4349052137991159230_63703440'
lib/redmine/sudo_mode.rb:65:in `sudo_mode'
When upgrading your Redmine version, you need to update the database schema for the new version. This is called migrating the database.
With a common configuration, you should thus run the following commands after an upgrade while inside the main Redmine directory:
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
Please see the Redmine Upgrade guide for more details on how to upgrade Redmine.

Jruby, Rails3.1, Sprockets - Same File error

On windows, running Jruby 1.6.4 - this issue occurs in Sprockets 2.0.0 and 2.0.2, Rails 3.1.0 and 3.1.1. Using therubyrhino as the js runtime, but this also occurs when using execjs (which correctly finds jscript).
Spin up a sample Rails project with a scaffolded controller. Start the server. Edit the controller's css.scss file with any change & save. Refresh the page. On Mac/Linux - things are fine. However, on windows you receive a "same file" error. This happens every time you change the css.scss file - and you must run: rake assets:clean to get past it.
Same behavior for coffeescript files (though again, only on windows). Asked the sprockets guys, but they recommended I ask the Rails core team (which I have). Decided to fork the questioning here as well.
Any thoughts?
BTW, here's a sample of the error:
ActionView::Template::Error (same file: C:/DEV/Information_Center/rubyw/edist3/tmp/cache/assets/sprockets%2F25f4cb117025b2fbc2fb480688c87da0.6816.15608 and C:/DEV/Information_Center/rubyw/edist3/tmp/cache/assets/D34/450/sprockets%2F25f4cb117025b2fbc2fb480688c87da0):
3:
4: <%= yield :page_title %> | foo.com
5: <%= stylesheet_link_tag "application" %>
6: <%= stylesheet_link_tag "article" %>
7: <%= javascript_include_tag "application" %>
8: <%= javascript_include_tag "article" %>
9: <%= csrf_meta_tags %>
app/views/layouts/article.html.erb:6:in `_app_views_layouts_article_html_erb___1475428847_7158'
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (0.0ms)
Workaround
Well - not much traction from the Rails core team just yet on this, but this workaround seems to allow sprockets and Rails to play a little nicer, via Jruby on Windows:
-add to development.rb
config.assets.cache_store = nil

Can't get asset pipeline working

I can't get the asset pipeline working for some reason. I get a 404 on request to both application.css and application.js. I'm using rails 3.1.0.rc6. Nothing special, just created a new project.
In my layout file:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
It's linking to /stylesheets/application.css and same with the js file. I'm using pow but also tried starting the server with webrick.
Any ideas?
Note: using sprockets 2.0.0.beta.15
Figured it out. I had to make an explicit require call to "sprockets/railtie"
You might find that adding
config.serve_static_assets = true
to your config/environments/xxx.rb will help.
To be more exact, add this to your Gemfile
gem 'sprockets/railtie'

Rails 3.1 error related to posix_spawnp when using the Albino gem and Redcarpet

I followed the Railscasts episode about adding code highlighting to an app using Redcarpet, Albino, and Pygments. It works as expected in development. On my test production server, however, I receive the following error:
ActionView::Template::Error (No such file or directory - posix_spawnp):
13: <div class="small_meta">
14: Posted on <%= #article.created_at %> by <%= #article.user.full_name %>. Topics: <%= #article.topic_list %>
15: </div>
16: <%= markdown(#article.body) %>
17: </div>
18:
19: <% else %>
app/helpers/application_helper.rb:19:in `block in syntax_highlighter'
app/helpers/application_helper.rb:18:in `syntax_highlighter'
app/helpers/application_helper.rb:13:in `markdown'
app/views/home/index.html.erb:16:in `_app_views_home_index_html_erb___3638324493742336500_70112578553660'
The error comes from the markdown() helper on line 16. The helper code is:
def markdown(text)
options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe
end
def syntax_highlighter(html)
doc = Nokogiri::HTML(html)
doc.search("//pre[#lang]").each do |pre|
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
end
doc.to_s
end
The problem is from the call to Albino. I'm at a loss as to how to fix this problem. It appears that Albino is unable to spawn the pygmentize process. When I run which pygmentize in Terminal.app, I see /usr/local/bin/pygmentize. /usr/local/bin appears in my paths when I run echo $PATH. The test production server is Apache/Phusion Passenger on OS X 10.7 Server.
What is going on here and how can I fix the posix_spawnp error?
I got the same error and fixed it by installing pygmentize. Make sure that you installed pygmentize into the correct Python interpreter. I'm running OS X 10.7 and I have 4 different python interpreters! You can find out which python you are actively running by typing
python --version
Also check read/write permissions on all pertinent directories, i.e. '/Library/Python/2.7/site-packages'

Resources