Spree admin panel not working - ruby-on-rails

I've install Spree gem and run it as it wrote in Getting Started. All works fine but if I want to go in the Products section in admin panel I have the following error:
Mysql2::Error: Unknown column 'variants.position' in 'order clause': SELECT `variants`.* FROM `variants` WHERE (`variants`.product_id IN (706676762,569012001,723959550,1025786064,1060500592,248786582,187438981,1035865702,459084718) AND (variants.is_master = 0 AND variants.deleted_at IS NULL)) ORDER BY variants.position ASC
Anyone faced that?
EDIT: Here is my Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2', '~> 0.2.11'
gem 'heroku'
gem 'thin'
gem 'spree', '~> 0.60.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem "test", :path => "test", :require => "test"

Normally when you install spree by following these steps, you should have some migration files inside db/migrate, one of them contain the missing column for your application :
class AddPositionToVariants < ActiveRecord::Migration
def self.up
add_column :variants, :position, :integer
end
def self.down
remove_column :variants, :position
end
end

Related

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?

undefined method `scan' for {"tooth"=>""}:Hash

I upgraded to rails4 from 3.2.2 and i now get this undefined method from my rabl template that id didn't get before the upgrade.
the "tooth" paramater on procedures is a set by a getter/setter method that is stored in the postgres database as a hstore hash named properties.
Not sure what has changed in rails4 to make this happen!
Any help would be much appreciated.
ERROR:
Showing /home/action/app/views/procedures/chart.json.rabl where line #1 raised:
undefined method `scan' for {"tooth"=>""}:Hash
Extracted source (around line #1):
1 object #procedures
2 attributes :buccal, :mesial, :occlusal, :distal, :lingual
Trace of template inclusion: app/views/procedures/_procedures_table.html.erb, app/views/procedures/chart.html.erb
Procedures model (getter and setter method for :tooth)
%w[tooth buccal mesial occlusal distal lingual].each do |key|
attr_accessible key
scope "has_#{key}", lambda { |value| where("properties #> (? => ?)", key, value) }
define_method(key) do
properties && properties[key]
end
define_method("#{key}=") do |value|
self.properties = (properties || {}).merge(key => value)
end
end
Gemfile:
source 'http://rubygems.org'
gem 'rails', '4.0.0.rc2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem "paperclip", "~> 3.0"
gem 'rabl'
gem 'activerecord-postgres-hstore'
gem "bugsnag"
gem 'country_select'
gem 'bullet', group: :development
# Asset template engines
gem 'sass-rails', '~> 4.0.0.rc1'
gem 'coffee-rails', '~> 4.0.0.rc1'
gem 'uglifier', '>= 1.3.0'
gem 'twitter-bootstrap-rails'
gem 'therubyracer', :platform => :ruby
gem 'less-rails'
gem 'jquery-ui-rails'
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
# Declarative Authorization
gem 'declarative_authorization'
gem 'protected_attributes'
# Authlogic
gem 'authlogic'
gem 'simple_form', '3.0.0.rc'
group :production do
end
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
gem 'rubber'
gem 'open4'
gem 'gelf'
gem 'graylog2_exceptions', :git => 'git://github.com/wr0ngway/graylog2_exceptions.git'
gem 'graylog2-resque'
Found the answer!! Rails 4 now has native support for Hstore, which is awesome but I hadn't realised. To fix my problem i merely followed this guide below which is great to set up my model with hstore and then deleted my getter/setter methods. http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013

ActiveAdmin - can't create model "Rating"

I have no idea why I get the error when I click on "New Rating". And it seems creation of other models gives the same error.
Here's the error msg: "no member 'rating' in struct"
The error is on line 316 of inherited_resources-1.4.0/lib/inherited_resources/base_helpers.rb
Full stacktrace: https://gist.github.com/depy/5330548
313 # extract attributes from params
314 def build_resource_params
315 parameters = respond_to?(:permitted_params) ? permitted_params : params
316 rparams = [parameters[resource_request_name] || parameters[resource_instance_name] || {}]
317 if without_protection_given?
318 rparams << without_protection
319 else
320 rparams << as_role if role_given?
321 end
Here's my Rating model:
class Rating < ActiveRecord::Base
validates_uniqueness_of :task_id, :scope => [:user_id, :user_role], :message => 'You have already rated this task'
validates_inclusion_of :user_role, :in => %w( client contractor )
validates_presence_of :task_id, :user_id
validates_presence_of :score, :message => 'Please rate your satisfaction'
belongs_to :task
belongs_to :user
end
Here's my ActiveAdmin Rating.rb:
ActiveAdmin.register Rating do
controller do; include StrongAdmin; end
# list
index do
column :user_id
column :task_id
column :comment
column :score
default_actions
end
# single
show do |rating|
attributes_table do
row :id
row :rater do
task_id = Rating.find(params[:id]).task_id
div do
Task.find(task_id).client.full_name + " [" + Task.find(task_id).client.id.to_s+"]"
end
end
row :user
row :user_role
row :task
row :score
row :comment
row :created_at
end
active_admin_comments
end
end
Here's my Gemfile:
source 'https://rubygems.org'
ruby "1.9.3"
gem 'rails'
gem 'pg' # Database (PostgreSQL)
group :assets do
gem 'sass-rails'
gem 'uglifier'
gem 'bourbon'
gem 'jquery-fileupload-rails'
gem 'jquery-rails'
gem 'asset_sync'
end
group :production do
gem 'honeybadger'
gem 'newrelic_rpm' # App monitoring
end
gem 'bcrypt-ruby' # Secure passwords
gem 'devise' # Authentication
gem 'unicorn' # Webserver
gem 'redis'# Session storage and Task applications
gem 'carrierwave' # File uploading
gem 'mini_magick' # Image processing
gem 'kaminari'# Pagination
gem 'turbolinks' # Pushstate and async loading
gem 'strong_parameters' # Attribute accessible replacement
gem 'dalli' # Memcached interface
gem 'fog' # CDN connector
gem 'activeadmin' # (user) administration
gem 'cancan' # Authorization
gem 'gibbon' # Mailchimp API wrapper
gem 'multi_json'
gem 'nokogiri' # HTML parser for error messages
gem 'pusher' # Hosted websockets
gem 'sidekiq' # Async processing
gem 'draper' # Decorator
gem 'lograge' # Improved logger
gem 'slim'
gem 'sinatra', :require => nil
group :development do
gem 'sqlite3'
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'quiet_assets'
end
group :test, :darwin do
gem 'rb-fsevent'
end
group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'capybara'
# gem 'capybara-webkit'
gem 'database_cleaner'
gem 'launchy'
gem 'faker'
end
I encountered the same issue. I updated ActiveAdmin from 0.5.1. to 0.6.0. The inherited resource gem was also updated to 1.4.0.
Since ActiveAdmin requires 1.3.1 or higher, you can lock the version in your gem
gem 'inherited_resources', "1.3.1"
This solved the issue for me.

unable to start webrick in windows xp

i got this error while i try to start the webrick server on my windows xp.
←[31mCould not find eventmachine-0.12.10 in any of the sources←[0m
←[33mRun `bundle install` to install missing gems.←[0m
I've already did a 'bundle install'. Also tried to install mongrel but it's not helping!
Gemfile codes:
source 'http://rubygems.org'
gem 'rails', '3.0.10'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
gem 'thin'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
Try running these commands and then try rails s again.
gem install specific_install
gem specific_install -l http://github.com/eventmachine/eventmachine.git

'no driver for sqlite3 found' in fresh rails install on windows 7 machine

My Gem file looks like this:
source 'http://rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec', '2.0.0.beta.18'
end
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
I get that error message when I try to go to /pages/home.
I am following the railstutorial guide and am at this point: http://railstutorial.org/chapters/static-pages#code:pages_routes
Btw, I am using sqlite3 as my db for now - if you were wondering.
Any ideas?
Edit: When I load the page, I am seeing a windows error message that says "ruby.exe - Entry point not found: The procedure entry point rb_str2cstr could not be located in the dynamic link library msvcrt-ruby191.dll".
Then it shows the error message in the browser.
I just had this issue on a windows vista system and got it working by downloading the precompiled binaries for windows from the sqlite website:
http://sqlite.org/download.html
once I downloaded the shell and the dll (I would have posted the links directly but this site will only allow me to post 1!!!) to my desktop I extracted them to the C:\Ruby192\bin folder and then ran:
gem install sqlite3-ruby
from the command line.
My issue is now fully resolved. Hope that helps.
I fixed this by re-creating my app, and in the initial bundle install, I changed the gem file to just have:
gem 'sqlite3-ruby', :require => 'sqlite3'
and not:
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
This seems to work. For whatever reason, that version of sqlite3 was not agreeing with my setup.

Resources