Why might columns added with migrations not show up in rails admin? - ruby-on-rails

I added some columns to a table using rails and rake, but they do not show up in rails admin. What might be a reason for this? I am successfully registering new objects using them...

Turns out I just needed to restart the rails server.

Related

Rake db:migrate and HTML generated not changing

I'm very new to RoR and building my first application. I used rails generate scaffold and created a table in database. Of course I did it wrong, wanted to make changes to the table, did it by rewriting the generated migration file. I think rake db:migrate works fine, because it's updating my schema, but there are no changes visible on the site. The view of the table didn't change, although the mechanism is different, I can't add anything now because it can't find the proper columns after I changed them. I have no idea how to fix it without rewriting the view files myself. Is it possible, I think I'm missing something?
You can undo/destroy scaffold by rails destroy scaffold scaffold_name and then re-generate scaffold with the columns you added on migration file. FYI, editing migration files is not a good practice.
You have two options, either you destroy the scaffolding that you've created with rails destroy scaffold ModelName or you change the views by hand. When you run rake db:migrate it won't do anything in the views.

Rails: Removing migrations/schema created by gem on uninstall

Is there an easy way to drop tables created by a gem when I am installing it? For my specific case I want to uninstall the gem and reinstall it but the old tables and data are still there. Right now I plan on dropping the created tables manually. Is there a way to see all the tables created by a gem?
There is no easy way to see all the tables created by a gem, unless they're namespaced within something sensible. For example, Forem namespaces all the tables with a forem_ prefix.
You would need to create a migration and drop the tables manually.

What is the equivalent of script/destroy scaffold User in Rails 3?

When I was using Rails 2, I did script/generate scaffold User to create the user model. Now I need to remove it, and I'm using Rails 3. I tried rails destroy scaffold User and rails destroy User, but these just created new rails projects named destroy. How do I do it? Thanks for reading.
Are you sure you are not running an older rails version at the time? Maybe forgot to switch to your Rails3 gemset with RVM?
It works fine here and this is the rails help output:
In addition to those, there are:
application Generate the Rails application code
destroy Undo code generated with "generate"

Ruby On Rails ActiveRecord SQL view into schema

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql.
The problem with this is that the view is not entered into the schema. So when I need to create my test database to run my tests against the view is not created. I then need to create it by running the sql statement. Is there a way to implement SQL views elegantly in ruby on rails?
My environment:
Ruby on Rails 3.0.3
PostgreSQL 8.3
The rails_sql_views gem is intended to solve this problem. It adds support to the schema dumper to include views, which means you can use them in your test database. I'm not sure how well it works in Rails 3, but the github issues list has a pull request that appears to add Rails 3 support.
Possibly. using config.active_record.schema_format = :sql may help.

multiple rails sites pointing to the same database

I want to run two rails websites (homepage and app) on the same database. However, migrations dont work because both websites try to use schema_migrations table at the same time.
Is it possible to override default schema_migrations table name? Any other ideas how to solve this problem?
The schema_migrations table name is kept in ActiveRecord::Migrator.schema_migrations_table_name, which you might me able to override (in environment.rb, initializers, etc.), but I haven't tried this.
On the other hand, if you use unique migration IDs in both application (default in 2.1 onwards, I think), migrations from two applications should work with a single schema_migrations table.
See this screencast for more information on how migrations work in Rails 2.1 and up.
I don't know when this was added but Rails 4 seems to support it now.
From the Rails documentation
config.active_record.schema_migrations_table_name lets you set a string to be used as the name of the schema migrations table.
If you are using a version of Rails where this is not supported then an alternative could be to use table_name_prefix. If you are using this approach, I'd make sure that your version of Rails prefixes schema migrations with table_name_prefix by looking at the source code.

Resources