Updating the Seeds File in Rails
As a matter of practice, it's important to continually update your seeds file as your data models change. This makes it possible to always have quick access to a comprehensive set of test data. In this guide we're going to make it possible to create sample users from the seeds file.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this last guide of this section I'd say the easiest one for the last one and that is that I notice that our seeds file has not been updated. Even after we added the concept of users. Let's come in and let's fix that. I'm going to close these out and going into our seeds file you can see that we have topics, that are created blog posts that are associated with them, skills portfolio items and all kinds of cool stuff like that. As great as that is, it also is kind of annoying because every single time that I run rails db:setup I have to go and register a new user. That's not an ideal scenario so I'm going to come to the very top and I'm going to create some users. First one is going to be an admin users I'm going to say

  email: "test@test.com",
  password: "asdfasdf",
  password_confirmation: "asdfasdf",
  name: "Admin User",
  roles: "site_admin"

puts "1 Admin user created"

  email: "test@test.com",
  password: "asdfasdf",
  password_confirmation: "asdfasdf",
  name: "Regular User",

puts "1 regular user created"

Let's go and let's clean out our database to verify that this works. So, I'll sayrails db:setup. As long as we don't have any syntax errors then we should now have a clean set of data and we should have our set up there in place with two types of users. That makes it way easier whenever we need to clean up our data. There's one other reason why this is so important and it's part of the reason why I am adding this guide to the course and that is for Devcamp I recently took on some additional developers to help specifically on the front-end. The front-end meaning you know the design components and those things. When I sent over access for the developers to start working on it they pulled it down. But because I had worked on Devcamp for a year or over a year just by myself I did not build a seed's file because I had built everything up completely from scratch. So I wasn't really using a seeds file and I didn't really need to because I already had all my data. Well, the problem came in when these other developers who had never worked on Devcamp before had to do the same thing and that would have made for a very long and not a fun process whatsoever. I had to go back create a seeds file that took care of every component and created test data for every single part of the site. It wasn't fun but it was very important and very helpful when it comes to letting other developers work on a project so I definitely recommend any project that you have in being able to have that kind of setup in place. I'm going to hit refresh here and let's make sure that our user works. As you can see right here we are not logged down. If I click login and login as test@test everything here should work signed in successfully so that all worked our fonts are looking good. Portfolio is working you can see all the data got cleaned up. All of our drag and drop interface works. Everything is fantastic. Congratulations in going through this. This is a lot of work. We're not completely done we're done with the build out of the application. Next, we're going to deploy it to the web. But as far as the core functionality we are all good to go. Very nice work in building this out. This was not a trivial application to build. It has multiple layouts it has a number of advanced Javascript components such as actioncable and having drag and drop interfaces and nested forms so very nice work. This is definitely a professional app and you built it using Rails best practices. Let's click done on this. Let's hit finish, deliver and except so we're all done here.

Let's also push up our last code commit. It's going to be
git status,
git add .,
git commit -m "Updated seed's file",
git push origin final-changes.

With that being pushed up we can go to github, go to the app which is at DevCamp-portfolio yours is going to be a little bit different. We can create a pull request and merge it.So, create pull request. We did a lot of work in this one and as you can see, looks like we have well over a dozen or so commits. So this is a decent chunk of work. Excellent job going through that I think that is definitely worth it. The changes we made really took the look and feel in the user interface and the user experience up to a whole other level. Now that is all live you can see that we have made 128 code commits throughout this process which is a lot of work.

Let's come

git checkout master,
git pull

This is going to pull down all of our changes and we are good to go. I will see you in the next section where we talk about how to deployer our app to the web.