middleman new article .slim fails - ruby-on-rails

I have been trying to use middleman article 'test' for example with the following config:
set :markdown_engine, :slim
activate :blog do |b|
b.sources = "posts/{year}{month}{day}-{title}.html.slim"
b.permalink = "{year}/{month}/{day}/{title}/index.html"
b.new_article_template = "lib/templates/article.html.slim"
b.layout = "layout-blog"
end
with gem file:
source 'https://rubygems.org'
source 'https://rails-assets.org'
ruby '2.1.0'
gem 'middleman', '~>3.3.3'
gem 'middleman-deploy'
gem 'middleman-pry'
gem 'middleman-blog'
gem 'slim'
gem 'pry'
gem 'font-awesome-middleman'
gem 'middleman-minify-html'
gem 'middleman-imageoptim', '~> 0.1.4'
gem 'rake'
gem 'highline'
gem 'rails-assets-jquery'
# Live-reloading plugin
gem 'middleman-livereload', '~> 3.1.0'
# For faster file watcher updates on Windows:
gem 'wdm', '~> 0.1.0', :platforms => [:mswin, :mingw]
# Windows does not come with time zone data
gem 'tzinfo-data', platforms: [:mswin, :mingw]
but now matter what I try the new article is always generated as a .markdown file.
thoughts?
current error message:
middleman article 'test2'
/Users/chrishough/BusinessNoConformity/CodeNoConformity/Blog/.bundle/ruby/2.1.0/gems/middleman-core-3.3.3/lib/middleman-core/renderers/markdown.rb:40:in `const_get': uninitialized constant Tilt::SlimTemplate (NameError)

Solved it by adding the correct extension as follows:
activate :blog do |b|
b.sources = "posts/{year}{month}{day}-{title}.html"
b.permalink = "{year}/{month}/{day}/{title}/index.html"
b.new_article_template = "lib/templates/article.html.erb"
b.layout = "layout-blog"
b.default_extension = ".slim"
end
Middleman Post

Related

"NameError: wrong constant name" after upgrading Rails 3.2 to 4.2

I'm upgrading a Rails app from 3.2 to 4.2 and when running tests, I'm getting NameError: wrong constant name (that's the full error message, nothing saying exactly what it's trying to constantize). Running a single test using --trace provides no additional info. It does seem like it gets as far as one of my factories (using FactoryGirl, pasted below), but the factory definition looks fine to me.
Test output:
$ bundle exec rake test TEST=test/unit/offer_test.rb --trace
** Invoke test (first_time)
** Execute test
** Invoke test:single (first_time)
** Invoke test:prepare (first_time)
** Execute test:prepare
** Execute test:single
DEPRECATION WARNING: Core extensions are deprecated and will be removed in Squeel 2.0. (called from /path/to/app/config/initializers/squeel.rb:11:in `block in <top (required)>')
DEPRECATION WARNING: [Devise] including `Devise::TestHelpers` is deprecated and will be removed from Devise.
For controller tests, please include `Devise::Test::ControllerHelpers` instead.
(called from include at /path/to/app/test/test_helper.rb:15)
DEPRECATION WARNING: [Devise] including `Devise::TestHelpers` is deprecated and will be removed from Devise.
For controller tests, please include `Devise::Test::ControllerHelpers` instead.
(called from include at /path/to/app/test/test_helper.rb:23)
Run options: --seed 32894
# Running:
EEE
Finished in 0.445273s, 6.7374 runs/s, 0.0000 assertions/s.
1) Error:
OfferTest#test_should_know_if_accepted_or_not:
NameError: wrong constant name
test/unit/offer_test.rb:8:in `setup'
2) Error:
OfferTest#test_should_not_be_able_to_create_offer_on_ended_listing:
NameError: wrong constant name
test/unit/offer_test.rb:8:in `setup'
3) Error:
OfferTest#test_should_create_new_from_hash_and_properly_set_all_attributes:
NameError: wrong constant name
test/unit/offer_test.rb:8:in `setup'
3 runs, 0 assertions, 0 failures, 3 errors, 0 skips
Coverage report generated for Unit Tests to /path/to/app/coverage. 1540 / 21634 LOC (7.12%) covered.
Gemfile:
source 'http://rubygems.org'
ruby '2.1.8'
gem 'rails', '4.2.8'
gem 'rake', '0.9.2.2'
# Gems used only for assets and not required in production environments by default.
gem 'sass-rails', "~> 5.0.6"
gem 'coffee-rails', "~> 4.2.1"
gem 'uglifier', ">= 1.0.3"
# Backwards compat gems used when upgrading from Rails 3 to 4.
gem 'protected_attributes', '~> 1.1.3'
gem 'activerecord-deprecated_finders', '~> 1.0.4', require: 'active_record/deprecated_finders'
gem 'json', '~> 1.8.6'
gem 'pg'
gem 'unicorn'
gem 'jquery-rails'
gem 'slim', '~> 3.0.7' # HTML templating
gem 'devise', '~> 4.2.1' # Authentication
gem 'sidekiq', '~> 4.2.10'
gem 'sidekiq-middleware', '~> 0.3.0'
gem 'sidekiq_status', '~> 1.2.0'
gem 'sinatra', :require => false # For Sidekiq monitoring
gem 'dalli' # memcached used for Rails.cache and sessions
gem 'kgio' # Nonblocking I/O for Ruby - performance boost to dalli
gem 'fog', '~> 1.40.0' # Storage on S3 for carrierwave
gem 'fog-aws', '~> 1.3.0'
gem 'carrierwave', '~> 1.0.0'
gem 'mini_magick'
gem 'filepicker-rails', '~> 2.1.0' # Image uploading
gem 'squeel', '~> 1.2.3'
gem 'stripe', '~> 2.4.0' # Payments
gem 'kaminari', '~> 1.0.1'
gem 'setler' # Settings
gem 'utf8-cleaner' # Rack middleware for cleaing up URL params
gem 'rakismet' # Filtering for spam via akismet.com
gem 'sanitize' # Add attributes like nofollow/target to anchors (per initializer config)
gem 'geokit-rails' # old free geocoding
gem 'geocoder' # new free geocoding
gem 'airbrake', '~> 6.0' # Error notifications
gem 'ancestry', '~> 2.2.2'
gem 'easy_money'
gem 'easypost', '~> 2.7.0' # Shipping
gem 'sift', '~> 2.1.0.1' # Fraud prevention
gem 'paypal-sdk-adaptivepayments' # Used for split payments.
gem 'paypal-sdk-adaptiveaccounts', :require => false # Verify PayPal email
gem 'paypal-sdk-rest', :require => false # REST API client
gem 'friendly_id'
gem 'font_assets'
gem 'griddler', '~> 1.4.0' # incoming emails for conversations
gem 'griddler-sendgrid', '~> 1.0.0'
gem 'aws-sdk', '~> 2.9.9'
gem 'text'
gem 'mailhopper'
gem 'audited-activerecord', '~> 4.2.2'
gem 'acts_as_list', '~> 0.9.5' # Used for sorting images
gem 'newrelic_rpm', '~> 4.1.0.333'
gem 'httpclient'
gem 'httparty'
gem 'rest-client', '~> 2.0.1' # for handling POST's to API images
gem 'hipchat'
gem 'musicbrainz' # Used to fetch album art.
gem 'bourbon', '~> 4.3.4' # Sass mixins libraries
gem 'armor_payments' # Escrow
gem 'countries', require: 'countries/global'
gem 'koala' # Facebook API tools
gem 'twilio-ruby' # Twilio text-messaging API
gem 'createsend' # Campaign Monitor integration
gem 'oink' # memory usage logger
gem 'browser', '~> 2.3.0' # used to detect mobile user-agent
gem 'redis-namespace', '~> 1.5.3'
group :development do
gem 'brakeman', :require => false
gem 'pry-rails'
gem 'redcarpet' # for YARD doc markdown formatting
gem 'yard'
gem 'rails-footnotes'
end
group :test do
gem 'database_cleaner'
gem 'email_spec'
gem 'minitest', '~> 5.10.1'
gem 'mocha', :require => false # Mocha needs to be required after the env is set up. See test/test_helper.rb
gem 'shoulda-matchers'
gem 'simplecov', :require => false
gem 'stripe-ruby-mock' # Mocking Stripe requests
gem 'webmock' # stubbing HTTP requests
end
group :development, :test do
gem 'byebug' # Debugger for Ruby >= 2.0
gem 'foreman'
gem 'forgery' # For randomly generating seed data in dev environment
gem 'factory_girl_rails', '~> 4.8.0' # Used mostly in tests
gem 'rspec', '~> 3.5.0'
gem 'rspec-rails', '~> 3.5.2'
gem 'faraday' # HTTP stubbing for vcr
# gem 'mailcatcher' # Capture and display local mailers. NOTE: Recommended to not be in Gemfile: https://github.com/sj26/mailcatcher#bundler
gem 'net-http-spy', :require => false
# gem 'rack-mini-profiler' # Displays a speed badge for every html page
gem 'vcr' # 'Playback' canned HTTP responses when testing
# Generate Database Diagram; Must install Graphviz to use locally (`brew install graphviz`, etc)
# gem 'rails-erd'
# rake db_diagram
end
test/unit/offer_test.rb
require 'test_helper'
class OfferTest < ActiveSupport::TestCase
def setup
#buyer = FactoryGirl.create(:user, username: 'test_buyer')
#seller = FactoryGirl.create(:user, username: 'test_seller')
#listing = FactoryGirl.create(:listing, auction: false) # <-- This is line 8, where the test throws the NameError.
#offer = FactoryGirl.create(:offer, buyer: #buyer, listing: #listing)
end
# ...snip...
end
Listings factory:
FactoryGirl.define do
factory :listing do |l|
l.association :category
l.association :seller, factory: :user
l.age { [3, 3, 9, 9, 10].sample }
l.album_art_url { media.present? ? "http://example.com/images/#{rand(1000)}.png" : nil }
l.album_art_back_url { media.present? ? "http://example.com/images/#{rand(1000)}-back.png" : nil }
l.auction_opening_bid { Forgery(:monetary).formatted_money }
l.auction_reserve_price { Forgery(:monetary).formatted_money }
l.bold { (rand(2) == 0) }
l.box_count 1
l.brand { Forgery(:name).company_name }
l.classified_asking_price_dollars { Forgery(:monetary).formatted_money(min: 1) }
l.condition { rand(10) + 1 }
l.description { Forgery(:lorem_ipsum).sentences(20) }
l.hit_count { Forgery(:basic).number(at_most: 69) }
l.media false
l.product_name { Forgery(:basic).text }
l.no_transaction_fee false
l.payment_methods ["PERS", "DISC"]
l.retail_price_dollars { Forgery(:monetary).formatted_money }
l.ship_from "29601"
l.ship_to "US"
l.shipping_methods ["UPS", "FDX"]
l.status Listing::STATUSES[:active]
l.title { Forgery(:basic).text }
l.auction_duration 7
end
factory :listing_with_shipping_info, parent: :listing do |l|
after(:create) do |listing|
address = FactoryGirl.create(:address, user: listing.seller)
listing.shipment.update_attributes(seller_address: address)
end
end
end
Rails 3.x used a test/unit/model_test.rb whereas rails 4.x uses a new test/models/model_test.rb so probably autoload is not finding the class because of that. Check the differences between the two here for 3.x and here for 4.x
This ended up being an issue with our application code. We had a Category model that had a #parent_name field, as well as a Category.parent_name(child = nil) class method that was conflicting with Rails core ext. Module#parent_name method.

Having errors with rake db:create

I'm trying to install fat free crm with ruby on rails on Windows 7, but when I put the command
rake db:create RAILS_ENV=production
it says
rake aborted!
LoadError: cannot load such -- 2.1/pg_ext
Normally, it would say what gem I should install, but not in this case.
How can I solve this error?
Edit:
A friend of mine suggested to uncomment mysql2 and comment pg on the Gemfile file in the proyect like this:
gem 'mysql2'
#gem 'sqlite3'
#gem 'pg'
But now I get this:
Unable to load the EventMachine C extension; To use the pure-ruby reactor, requi
re 'em/pure_ruby'
C:/Ruby21/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': ca
nnot load such file -- 2.1/rubyeventmachine (LoadError)
Have any ideas of why this happends?
Here is my Gemfile:
source 'https://rubygems.org'
# Uncomment the database that you have configured in config/database.yml
# ----------------------------------------------------------------------
gem 'mysql2'
# gem 'sqlite3'
# gem 'pg'
# Removes a gem dependency
def remove(name)
#dependencies.reject! {|d| d.name == name }
end
# Replaces an existing gem dependency (e.g. from gemspec) with an alternate source.
def gem(name, *args)
remove(name)
super
end
# Bundler no longer treats runtime dependencies as base dependencies.
# The following code restores this behaviour.
# (See https://github.com/carlhuda/bundler/issues/1041)
spec = Bundler.load_gemspec( File.expand_path("../fat_free_crm.gemspec", __FILE__) )
spec.runtime_dependencies.each do |dep|
gem dep.name, *(dep.requirement.as_list)
end
# Remove premailer auto-require
gem 'premailer', :require => false
# Remove fat_free_crm dependency, to stop it from being auto-required too early.
remove 'fat_free_crm'
group :development do
# don't load these gems in travis
unless ENV["CI"]
gem 'thin'
gem 'quiet_assets'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rvm'
#~ gem 'capistrano-chruby'
#~ gem 'capistrano-rbenv'
gem 'guard'
gem 'guard-rspec'
gem 'guard-rails'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end
end
group :development, :test do
gem 'rspec-rails', '~> 2'
gem 'headless'
gem 'debugger', :platforms => 'mri_19' unless ENV["CI"]
gem 'byebug', :platforms => ['mri_20', 'mri_21'] unless ENV["CI"]
gem 'pry-rails' unless ENV["CI"]
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem "acts_as_fu"
gem 'factory_girl_rails'
gem 'zeus' unless ENV["CI"]
gem 'coveralls', :require => false
gem 'timecop'
end
group :heroku do
gem 'unicorn', :platform => :ruby
gem 'rails_12factor'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'execjs'
gem 'therubyracer', :platform => :ruby unless ENV["CI"]
end
gem 'turbo-sprockets-rails3'
It sounds like you are missing the pg gem from your Gemfile. Is it in the development group?
Can you post your Gemfile?
Uncomment #gem pg.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' is a separate error. Where did you get that Gemfile?

digest_path & asset_digest_path not allowing digest URLs

I have been having this pretty rough time with assets on production. It came down to me trying to override the sprokets helper module to try and see what was up... When I re-wrote it to the following:
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
It would not run. I tried it in my local environment, and it runs perfectly. Is there a reason the production environment would not allow my assets to render in digest form, but my local environment would? This is related to what this gent was asking...
Rails 4.0.3 generating incorrect asset paths with asset_sync
Here is the error I receive after trying to override that method (which doesn't have an error when running with RAILS_ENV=development):
ActionView::Template::Error (undefined local variable or method `digest_path' for #<#<Class:0x000001034a99e0>:0x000001034a81d0>):
Asset Gems in Gemfile for reference:
source 'http://rubygems.org'
# ruby '2.1.1'
gem 'rails', '4.0.4'
gem 'jbuilder', '~> 1.2'
gem 'devise'
gem 'devise_invitable'
gem 'figaro'
gem 'mysql2'
gem 'simple_form'
gem 'kaminari'
gem 'statistics'
gem 'possessive'
gem 'geocoder'
gem 'nokogiri'
gem 'asset_sync'
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'ledermann-rails-settings', :require => 'rails-settings'
gem 'public_activity'
group :assets do
gem 'therubyracer'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'guard-bundler'
gem 'guard-rails'
gem 'quiet_assets'
gem 'rails_layout'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
end
group :test do
gem 'email_spec', '>= 1.4.0'
gem 'launchy', '>= 2.2.0'
gem 'capybara', '>= 2.0.3'
gem 'database_cleaner', '>= 1.0.0.RC1'
gem 'cucumber-rails', '>= 1.3.1', :require => false
end
group :production do
gem 'rails_12factor'
end
gem 'rspec-rails', '>= 2.12.2', :group => [:development, :test]
gem 'factory_girl_rails', '>= 4.2.0', :group => [:development, :test]
gem 'teaspoon', '>= 0.7.4', :group => [:development, :test]
gem 'cancan', '>= 1.6.9'
gem 'rolify', '>= 3.2.0'
gem 'stripe-rails'
gem 'faker'
gem 'open4'
gem 'unf'
When I run this in development mode, it runs completely fine. When I run this through production mode (even with the same config file) it does not inherit the View properties like digest_path or asset_digest_path is null or manifest, etc.
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
if digest_path = asset_digest_path(path)
path = digest_path if true # BUG: digest assets doesn't work on live, let's just bake it
path += "?body=1" if options[:debug]
File.join(assets_prefix || "/", path)
else
super
end
end
def asset_digest_path(path, options = {})
if manifest = assets_manifest
if digest_path = manifest.assets[path]
return digest_path
end
end
if environment = assets_environment
if asset = environment[path]
return asset.digest_path
end
end
end
end
end
end
module ActionView
module Helpers
module AssetUrlHelper
def compute_asset_path(source, options = {})
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
File.join(dir, source)
end
end
end
end
Hopefully this will help save my fellow programmer friends some head banging :D
I was uploading the files to S3, I didn't realize that the manifest wasn't loaded by Rails. You can have all your production settings right (like above and in other threads), but if you don't have the manifest.json file readable by Rails, it will still generate /javascript/* (example) urls.
I was still having trouble with multi_json gem's latest version, so I downgraded it to 1.7.8 and it works fine.
gem 'multi_json', '1.7.8'
That's so it can read the manifest.json file which rake assets:precompile creates.
There is a debate on this sprockets thread https://github.com/rails/sprockets-rails/issues/107 on whether your manifest file should be in git or just on a deploy script, do what suits you best, just make sure it is findable in:
/public/assets/manifest.json
or specifiy it yourself with
config.assets.manifest = '...'
That may or may not be depricated.
Cheers!

ActiveAttr stops working on production server

I have created a simple model for handling a contact form:
class ContactForm
include ActiveAttr::Model
attribute :name
attribute :email
attribute :message
attr_accessible :name, :email, :message
validates_presence_of :name, :email, :message
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\#([-a-z0-9]+\.)+[a-z0-9] {2,4}$/i
end
It works fine on the development environment, but gives me an error on the production server, logged in the unicorn log:
E, [2013-01-26T18:15:42.724973 #8940] ERROR -- : uninitialized constant ContactForm::ActiveAttr (NameError)
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'
# gem 'acts_as_tree', :git => 'git://github.com/amerine/acts_as_tree.git'
gem 'closure_tree'
gem 'kaminari'
gem 'friendly_id'
gem 'slim'
gem 'gmaps4rails'
gem 'devise'
gem 'omniauth'
gem 'oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'simple_form'
gem 'pg_search'
gem 'stamp'
gem 'acts-as-taggable-on', '~> 2.3.1'
gem 'rmagick'
gem 'carrierwave'
gem 'active_attr'
gem 'select2-rails'
# gem 'roo'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'compass-rails'
end
group :development do
gem "better_errors"
gem "binding_of_caller"
gem 'guard'
gem 'letter_opener'
end
group :test do
gem 'minitest'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'bullet', :group => :development
gem 'rack-mini-profiler'
I had the same problem and the fix for me was to specify the version of active_attr in my gemfile.
gem 'active_attr', '0.7.0'
I found an issue on GitHub where someone else had the same problem here.
I have the same problem in development environment.
I followed this step-by-step tutorial https://github.com/thomasklemm/email_form_rails.
When I try to create a new message in console I get :
m=Message.new
NameError: uninitialized constant Message::ActiveAttr
I use Rails 3.2.1, active_attributes gem version is 0.0.1.
EDIT
My fault it seems I made a mistake when installing the gem (not the good one)
change gemfile from
gem 'active_attributes','0.0.1'
to
gem 'active_attr', '0.0.7'
Now it seems to work...

jruby on rails with warbler and tomcat and windows

I tried to deploy an application.war file into webapps/ in the tomcat folder and started up the server. When i try to open http://localhost:8080/relConnections it shows on the screen that "something went wrong". I deleted the common index.html in the public folder in usual rails apps and tchanged the root to my home page.
When i see the log file it says the following:
"An exception happened during JRuby-Rack startup private method `gsub' called for nil:NilClass
--- System
jruby 1.6.7"
and three or four more excecption saying the same lines gsub nil:NilClass for all of those.
Here is my Gemfile
source 'http://rubygems.org'
gem 'jruby-jars', '1.6.7'
gem 'warbler', '1.3.2'
gem 'rails', '3.1.3'
gem 'rake', '0.9.2.2'
gem 'jruby-openssl', '0.7.5', :platforms => :jruby
gem 'json', '1.6.5', :platforms => [:jruby, :mingw, :mingw_19]
gem 'therubyrhino', :platforms => :jruby
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'activerecord-jdbc-adapter', '1.2.2'
gem 'activerecord-oracle_enhanced-adapter', '1.4.0'
gem 'mechanize', '1.0.0'
gem 'nokogiri', '1.5.0'
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :development do
gem 'ruby-debug-base', '0.10.4'
gem 'ruby-debug-ide', '0.4.17.beta8'
gem 'pry', '0.9.7.4'
end
group :test do
gem 'turn', '0.8.3', :require => false
gem 'minitest', '2.11.0'
gem 'timecop', '0.3.5'
end
gem 'jruby-pageant', '~>1.0.2'
gem 'net-ssh', '~>2.5.2'
And here is my warble.rb
Warbler::Config.new do |config|
#commented code
config.dirs = %w(app config lib log vendor tmp)
#more commented code
end
Let me know if iam missing any gems or anything else here.
Thanks
I think you may try to set the jruby version to 1.9. In the warble.rb
config.webxml.jruby.compat.version = "1.9"

Resources