Add boolean selector to existing custom engine

47 views
Skip to first unread message

J. Chase Freeman

unread,
Apr 10, 2014, 8:46:34 PM4/10/14
to refine...@googlegroups.com
Last one today I promise.

I have been working on this for a while and could use some direction. I have a custom generated engine that works fine, but the clients wants to add some functionality. I have gone through the vendor directory multible times, reviewing every file, attempting to add the necessary components, but have had no luck.

What am I missing? Are there any guides on editing or adding functionality to a custom generated engine.

Thank you.

Christian Aust

unread,
Apr 11, 2014, 4:44:09 AM4/11/14
to refine...@googlegroups.com
ActiveRecord maps columns of the database table to attributes of your model, so what you want to achieve first is adding a column to the database. Rails uses migrations [1] to do so:

$ rails generate migration AddColumnToModel my_column_name:boolean

This will create a migration file in db/migrate in your root folder. Move it into your engine's db/migrate directory. Run `rake <engine_name>:install:migrations` to re-add it to your main app again and run `rake db:migrate` to eventually perform the migration.

Now you need to modify your model: Add the new column name to attr_accessible and extend the _form partial to include the new attribute, too. It should be working now, you should be able to set the new boolean value in the backend. HTH

Christian

J. Chase Freeman

unread,
Apr 13, 2014, 8:15:58 PM4/13/14
to refine...@googlegroups.com
Allright, I have been working on this for a while now. And I can not seem to migrate the db.

I could not get  Run `rake <engine_name>:install:migrations` to work, and after reading through the documentation I found that 'rake railties:install:migrations' would run, but after that, when I run 'rake db:migrate' I get this:

==  AddColumnToModel: migrating ===============================================
-- add_column(:models, :my_column_name, :boolean)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: models: ALTER TABLE "models" ADD "my_column_name" 

Any thoughts?



--
You received this message because you are subscribed to the "Refinery CMS" Google Group.
To post to this group, send email to refine...@googlegroups.com
 
http://www.refinerycms.com
---
You received this message because you are subscribed to a topic in the Google Groups "Refinery CMS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/refinery-cms/x_sFPGV4mTk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to refinery-cms...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/refinery-cms/bffb271e-44fa-40c4-b51d-9a2663e7e5d1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Cynthia Kiser

unread,
Apr 13, 2014, 8:29:06 PM4/13/14
to refine...@googlegroups.com
Quoting J. Chase Freeman <j.ch...@gmail.com>:
> Allright, I have been working on this for a while now. And I can not seem
> to migrate the db.
>
> I could not get Run `rake <engine_name>:install:migrations` to work, and
> after reading through the documentation I found that 'rake
> railties:install:migrations' would run, but after that, when I run 'rake
> db:migrate' I get this:
>
> == AddColumnToModel: migrating
> ===============================================
> -- add_column(:models, :my_column_name, :boolean)
> rake aborted!
> StandardError: An error has occurred, this and all later migrations
> canceled:
>
> SQLite3::SQLException: no such table: models: ALTER TABLE "models" ADD
> "my_column_name"
>
> Any thoughts?

Looks to me like you didn't replace the boilerplate from the example
about creating a migration - unless of course you really do want a
column named "my_column_name". Try editing the migration in your
custom engine to be what you really want - the real table name and
actual column name, then rerun the 'rake railties:install:migrations'
command and see if that makes the change you want. (You will want to
remove the files that have 'my_column_name' in them.

--
Cynthia N. Kiser
c...@ugcs.caltech.edu

J. Chase Freeman

unread,
Apr 13, 2014, 8:36:20 PM4/13/14
to refine...@googlegroups.com
I tried it a few times with the correct name in place. Then one last time with the boilerplate name still in place. I keep getting the same error regardless of what I name it.

But im become quite desperate, and will change the name as you have suggested and give it another shot.

J. Chase Freeman

unread,
Apr 13, 2014, 8:43:27 PM4/13/14
to refine...@googlegroups.com
I tried again with the name 'active' and recived the same error. This is the result running trace.

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
==  AddColumnToModel: migrating ===============================================
-- add_column(:models, :active, :boolean)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: models: ALTER TABLE "models" ADD "active" 

I know its Sunday, so thank you very much for looking at this.

Philip Arndt

unread,
Apr 13, 2014, 10:21:43 PM4/13/14
to refine...@googlegroups.com
Maybe you didn't name the table with the right name.. you have to remember to put the full namespace in for example it's usually something like refinery_models or refinery_model_aeroplanes.  Check the migration that came along from when you first generated the extension for the existing name. :)

J. Chase Freeman

unread,
Apr 14, 2014, 4:39:39 PM4/14/14
to refine...@googlegroups.com
Everyone is always so helpful I wanted to give a heads up on how I got it working. I ended up deleting the entire engine, then rebuilt it with the extra features in tact. I was a perfectly reasonable solution becuase there really wasn't much content in the DB. I know that editing a pre-existing engine is a skill I need, but today Im ok.

Thank you.

Philip Arndt

unread,
Apr 14, 2014, 7:06:47 PM4/14/14
to refine...@googlegroups.com
Awesome glad you got it sorted. Sometimes nuking it from orbit is the best policy.

Josiah Palmer

unread,
Apr 21, 2014, 2:57:54 PM4/21/14
to refine...@googlegroups.com
I realize that you've already resolved your issue but figured I would go ahead and post this for other people with the issue. I spent a little while today trying to figure out a fix for the same issue today but with a PostgreSQL database. I found that the issue is in the actual migration file. When I put in "rails g migration AddRateToServices rate:decimal" for my custom engine, it generated it, however it assumed the table name was "services" and generated the migration file accordingly. The fix that I found was to manually edit the migration file and change the table name to :refinery_services . I'm not sure if that's the correct protocol for this but it worked for me. Hope that will help for anyone else dealing with this issue.
Reply all
Reply to author
Forward
0 new messages