aspose file tools*
The moose likes Ruby and the fly likes [Rails] Question about flow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "[Rails] Question about flow" Watch "[Rails] Question about flow" New topic
Author

[Rails] Question about flow

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Did a little bit of Rails over the weekend for the first time in years. I'm very well versed in Grails so I'm having a few snags regarding the work flow of getting up and running. I created a new project and then I ran the initial rake db:create command. After this is where my questions are.

Following an online guide from the official web site, I created a new domain and gave it some initial properties. Then I ran rake db:migrate. Everything worked fine. I then went and created a new domain that is related to my first domain. And then I started getting all confused because I can't just go into the domain and set the associations like I want (has_many, belongs_to). I also have to manage the migrate files and get those set up correctly, which I've been unable to do.

So, this flow isn't working for me. Although it might be trivial for a more seasoned Rails person. And I can see how rake is a good thing later on down the road, but I'm having a hard time finding its usefulness when just trying to setup your primary domains. So my preferred way of working would be this....

create rails project
rake db:create
create domain
create domain
create domain
.....
when I think they are "pretty close" to what I initially need, then run rake db:migrate. That way, my initial schema file is correct and I don't already have N number of migration files to deal with, nor do I have to manually create migration files for associations up until this point. Does that make sense to anyone?


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I should add that part of my confusion with rake is that I created the many side of a one-to-many first. If I had created the 1 side first, it wouldn't have been a big deal. But in the real world, you don't always know exactly what these associations are going to be like right up front.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There's a rake db:rollback command that will reverse the last migration, assuming your migration file included the self.down definition (in many cases the down definition is dropping a table or a couple columns). I've mentioned using vim before - the railsvim plugin has a nice command :Rinvert that will create the down automatically based on the contents of the up. There might be a similar plugin for your editor/IDE of choice.

It's common, while working on a single feature, to bounce back and forth between rake db:migrate (which runs all migrations that have not yet been run) and rake db:rollback to peel back the latest migration until you know you'll got a migration file that is correct.

Getting the associations set up is a matter of adding a some_other_table_id integer column. The documentation here is fairly straight-forward:
http://guides.rubyonrails.org/association_basics.html


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Rails] Question about flow