Вопрос

So i generated a scaffold for my ruby on rails project only to find out that i had added a column i no longer need.

i generated a migration and removed the extra column.

I then removed the column everywhere it was called in the code.

But when i run a "rake test" i'm getting several errors and they seem to be pointing at this non-existent column, I modified the controller_test.rb

  @foo = foos(:one)
  @update = {
  title:       'Lorem Ipsum',
  description: 'Wibbles are fun!',
  image_url:   'lorem.jpg',
  start_date:  '12/12/13',
  end_date:    '13/12/13'
  }

i also modified the should create test and should update test

 test "should create foo" do
 assert_difference('Foo.count') do
  post :create, foo: @update 
 end

and this

 test "should update foo" do
 put :update, id: @foo, foo: @update 
 assert_redirected_to foo_path(assigns(:foo))
 end

any help would be really appreciated, if more info is required i can supply more

Это было полезно?

Решение

I found the problem after some hours of persistence.

whilst the column is removed from the table there were still reference's to it in the project, in my case it was here test/fixtures/foo.yaml

to find out everywhere the specific line is (if your IDE does not have search functions) mentioned go to your git bash where your working from and run

 $ grep -r "search term" *

it picks out the Dir that the search term lies in, after this its just a simple case of just removing all references for it

note that this command give allot of lines what your looking for sits at the bottom.

Другие советы

Are you new to rails? If yes, could you tell me what guide are you following.And how you generated the scaffold

Scaffold created all these files

  invoke  active_record
  create    db/migrate/20130704111616_create_products.rb
  create    app/models/product.rb
  invoke    test_unit
  create      test/models/product_test.rb
  create      test/fixtures/products.yml
  invoke  resource_route
   route    resources :products
  invoke  scaffold_controller
  create    app/controllers/products_controller.rb
  invoke    erb
  create      app/views/products
  create      app/views/products/index.html.erb
  create      app/views/products/edit.html.erb
  create      app/views/products/show.html.erb
  create      app/views/products/new.html.erb
  create      app/views/products/_form.html.erb
  invoke    test_unit
  create      test/controllers/products_controller_test.rb
  invoke    helper
  create      app/helpers/products_helper.rb
  invoke      test_unit
  create        test/helpers/products_helper_test.rb
  invoke    jbuilder
  create      app/views/products/index.json.jbuilder
  create      app/views/products/show.json.jbuilder
  invoke  assets
  invoke    coffee
  create      app/assets/javascripts/products.js.coffee
  invoke    scss
  create      app/assets/stylesheets/products.css.scss
  invoke  scss
  create    app/assets/stylesheets/scaffolds.css.scss

Files created by active_record, scaffold_controller and test_unit could cause an error in the test try inspecting them to see if there is anything there that should not be.

Also try deleting the development.sqlite3 and test.sqlite3 and run a rake db:migrate again.

There is also the rails destroy command that will remove all the autogenerated files

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top