Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Generate a Scaffold

Simple question that's actually, likely, complex. Typos when building an app?

Let's say I'm halfway through the Generate a Scaffold video when I realize that I named one of the fields "descripton" instead of "description. You know, like this:

typo-duh

I understand just enough about Ruby on Rails so far to think, "uh oh, that might actually involve changing a bunch of files" but also to think, "hey, maybe that's a quick fix."

Any ideas here? I'm hoping I don't have to start over just to fix it.

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The short way would be to edit the view and override the label. Normally the label is generated based on the name of the field, but you can pass it as a separate attribute like this:

<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation, size: 40 %>

This would normally put a label "Password Confirmation", but the additional parameter, a string, overrides it. If you're unsure how to do it in your particular project, just post your code for the form and I will help you out.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The hard way would be to add a migration that changes the name of the column. This would also involve doing lots of changes in some other files and resetting the database. I did it once, it's doable, but I wouldn't recommend it to a beginner.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

http://stackoverflow.com/questions/21418702/changing-column-names-in-a-migration-file

Then do a search in all the project files and change the wrong word into a proper one (but not in the old migration file! these should never be modified). Copy your project somewhere or use Git to save the state before doing such changes.

Yeesh. I made the mistake of trying to just do a find and replace in my text editor, and it's pretty broken now. Thank goodness we used Git on this: now I get to learn how to go back to an older commit and start from there. :grinning:

Blargh! Typos!

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Yup, mistakes are good, because we learn other stuff at the same time ;). I learned a lot about git's rebase and reflog when playing around with my mistakes in code ;).