Spree Extension Scaffold - spree

I have created a a spree application and used one existing extension spree_news by cloning it to my spree application folder, now when i try to create a scaffold or a resource inside the spree_news extension by trying:
wapnil#swapnil-pc:~/ecommerce/spree_news$ rails generate scaffold oerp
Pname:string Pdesc:text Pprice:float
the following error is encountered:
/home/swapnil/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- rails/engine/commands (LoadError)
from /home/swapnil/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from script/rails:8:in `<main>'
Please Help!!

The script/rails file in your extension is wrong and should be this. This is due to a bug in Spree that will be fixed in the next release.

Related

How to migrate pending migrations in rails?

Im working on ruby on rails open source projects. So after cloning from github i setup the mentiones pg database in Gemfile by using command rails db:create successfully it created the database . Now there are 809 migration files , to migrate with postgres database i ran the
rake db:migrate
Im getting the below error
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class CreateEvents < ActiveRecord::Migration[4.2]
D:/Freelance/pupilfirst/db/migrate/20131204110627_create_events.rb:1:in `<top (required)>'
Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class CreateEvents < ActiveRecord::Migration[4.2]
D:/Freelance/pupilfirst/db/migrate/20131204110627_create_events.rb:1:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
there are 809 migrations files are there . so can anyone help me out from this. my rails version is ``rails 6.1.5.1`

How to generate a test directory using Rails 4 for minitest procedures?

I have a question in regards to generating a test directory in my Rails App, I intend on doing unit tests and functional tests all relying on minitest, but I have noticed that rails did not automatically generate a test directory in my app. How do I go about configuring the test environment, so I can properly add a test directory to my app for minitest procedures?
If you execute the command
rails new some-app-name
you should see in the output in the terminal/shell the information that the test directory was created.
.....
create test/fixtures
create test/fixtures/.keep
create test/controllers
create test/controllers/.keep
create test/mailers
create test/mailers/.keep
create test/models
create test/models/.keep
create test/helpers
create test/helpers/.keep
create test/integration
create test/integration/.keep
create test/test_helper.rb
.....
Can you post the command you ran at the shell to create the app ?
Some good background (and current) information on setting up minitest with rails is in Matt Brictson's Blog . In this blog post there are some other suggestions about setting up the enhanced display from minitest runs and also recommendations on other gems to use in your rails Gemfile.

Simplecov report ignores folders in /app directory

I use simplecov to measure coverage for my Rails 4.0.11 app. I use Ruby 2.0.0. I noticed that some subfolders of /app are ignored by simplecov and I can't figure out why.
test_helper.rb:
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
I have tried upgrading to Ruby 2.1 after reading some posts that that might help, but still some subfolders are being ignored. I also tried to move the SimpleCov.start into a .simplecov file at the root of my project, but the problem persists. I also tried to remove the rails configuration and add filters and groups myself, but the ignored ones just turn up empty.
Folder like /mailers, /serializers, /presenters are all ignored. It does pick up on /models and /controllers.
I had the same issue. in your rails environments/test.rb make config.eager_load = true. this will load every ruby files while app booting.

rails 4 app in subdirectory - precompiled assets point to root instead of subdirectory

Rails 4.1.1 production installation using Apache/Passenger configured to run rails app in a subdirectory "/myapp" instead of the root of the site.
All links in the app work fine, but in production references to assets in SCSS file, for example
background-image: image-url('logo.png');
get compiled to:
background-image: url("/assets/logo-<hash>.png");
instead of:
background-image: url("/myapp/assets/logo-<hash>.png");
I tried doing something like this when precompiling assets:
RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/myapp rake assets:precompile
but that had no effect.
I also tried setting config.relative_url_root in the config/environments/production.env file, with no luck.
The Rails guides say to set config.action_controller.relative_url_root, but that results in a missing method error.
I eventually gave up and embedded the image in the CSS file by using:
background-image: asset-data-url('logo.png');
which works, but only by avoiding the subdirectory problem altogether.
I know Rails makes you pay for not following conventions, but having an app in a subdirectory is not exactly outlandish.
I've seem all kinds of posts on this problem, but it's hard to get a straight answer. It seems to have been fixed a few times for earlier versions of Rails, but it's not clear if the fixes ever got into the standard Rails distribution.
In our case, we were able to make two changes, which seem to be working for us in Rails 4.1.6 :
1) In application.rb, assume there is a module named "MyAppName < Rails::Application". In here, we have
config.relative_url_root = "/myapp"
2) In config.ru:
map MyAppName::Application.config.relative_url_root || "/" do
run Rails.application
end
Without the config.ru update, things don't work properly.
After adding the jquery-ui-rails gem to another app deployed in a subdirectory, I had the same problem with the assets referred to by the built-in CSS for jQuery UI. I refused to modify the 3rd-party CSS files just to fix this problem, especially since Rails seems to be handling all paths (other than asset paths) correctly out of the box.
After pulling my hair out for some time, I don't know what prompted me to re-run the rake assets:precompile task exactly as given here. To my complete surprise, everything worked perfectly, both my own image URLs and jQuery UI's.
What made the difference? If I call the rake script from the app's bin folder as shown below, all the asset URLs are built incorrectly, without the subdirectory.
RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/myapp bin/rake assets:precompile
If instead I run rake via bundle exec, as follows, all the asset paths are generated correctly, including the subdirectory.
RAILS_RELATIVE_URL_ROOT=/myapp RAILS_ENV=production bundle exec rake assets:precompile
As to why this is happening, I can only conclude that running bin/rake does not load the right gems.

Spree - Can't find _form.html.erb

I am going over the spree tutorial and trying to override the product edit admin page in spree using Deface. I cannot locate the following file path in spree:
spree/admin/products/_form.html.erb
From your Spree directory type:
ls `bundle show spree_backend`/app/views/spree/admin/products/_form.html.erb
That's where the file is located on your system.
Here is the source of the file from the latest Spree:
https://github.com/spree/spree/blob/v2.2.1/backend/app/views/spree/admin/products/_form.html.erb