Need help with Unit 3: Associations I > Step 3


#1

Unit 3: Associations I > Step 3

I am stuck in step 3.
I am typing: rake db:migrate in terminal ... but rake is being aborted because of some syntax error.

Is anyone able to tell me whether I am doing this correctly?

Thank you.


#2

Hi Edgar,

Get rid of your extra loop, it's what's causing the problem. Your db/migrate file should look like this:

Spoiler! (Click to view)

class CreateTags < ActiveRecord::Migration
  def change
    create_table :tags do |t|
      t.string :title
      t.string :image

      t.timestamps
    end
  end
end

#3

It seems to have gone better this time, but still aborting something...

Should line 3 include |t, i| instead of |t| (t for title and i for image)?


#4

@pandolfino No, just |t|, although I understand your thinking. It's all in one loop that creates the database columns :slight_smile:


#5

Thanks.

rake db:migrate is still being aborted. (I typed the code you gave me). I even tried adding a 4th 'end'.

Error I am getting is:

SyntaxError: /home/ccuser/workspace/learn-rails-one-to-many/db/migrate/20160901094825_create_destinations.rb:10: syntax error, unexpected end-of-input, expecting keyword_end

Help.


#6

@pandolfino It sounds like you're missing an end at the bottom of the file. Could I see your updated code?


#7

Here we go...

(a) Create_Tags

(b) Create_Destinations (also having problems, but yet to remove the extra loops...)

Thank you so much! :slight_smile:


#8

@pandolfino In your create_tags.rb file, you should put t.string :title on it's own line.

Then, for the destinations file, look at your tags file. See how there's one loop, create_table ... do |t|? Do EXACTLY that for destinations, then put t.string :[whatever] inside the loop, each thing on it's own line. Like this:

def change
  create_table :destinations do |t|
    t.string :title
    # now do the image and description

    t.references :tag
    t.timestamps
  end
end

#9

Is the reason why you only have 2 ‘end’s … one end for def, and one end for loop (so the end corresponds to the loop rather than to every column that is being added to the database)?

Ta.
Edgar


#10

@pandolfino That's correct, although the snippet I showed you is missing the first line and the last line, so there are actually three ends, the last one to close line 1 - sorry if that made it more confusing, wasn't my intention.


#11

It's not you, it's me who should apologise. I am slow to understand... :cry:

It is step 3 that I am getting stuck on.
Why is rake being aborted when I type: rake:db migrate?


#12

@pandolfino No no, it's fine :slight_smile:

OK, your the file for Tags in db/migrate is perfect! Looking at the error, it looks like the issue has moved on to the Destinations file in db/migrate, so could I see the code in that file please?


#13

Here is the code in the Destinations file.

When I type:

rake db:migrate (in the bash below) the rake is aborted.


#14

@pandolfino That's almost perfect, just change |n| on line 3 to |t|, and it should work :slight_smile:


#15

No, still not working :sob:
Where do I find my :controller key? I am totally lost now.

This is how the code in my routes file looks: Would the :controller key be in here?


#16

@pandolfino Yay, we're on to a different error! :tada: At least it's not the same problem anymore :slight_smile:

First, remove line 2 (resources :tags). Then, change what is line 3 right now (line 2 after you do the first step) to look like this:

get 'tags' => 'tags#index'

You may also need to add something for tags#show, like this:

get 'tags/:id' => 'tags#show'

but I'm not sure if you're there quite yet.


#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.