0

I'm learning RoR, I've read some tutorials (railstutorial for the first one), but I've a problem to define the logic layout of the my first simple website.

The structure is:

When you go to mysite.com you see a welcome page with the signup form or the link for login. If you signup or you login into the site, you are at mysite.com/dashboard and you see a list of your messages. You can go to mysite.com/$username and you see a page with a form where you can write a message for the $username.

Stop. That's it. It's very simple, I know, but is for learning.

The problem is this: I'm new to MVC paradigm and I don't know how structure the logic layout of my app. Of course there'll two models: User and Message. But for controllers? And which functions in any controllers? Should I use scaffolding? Please give me a help, I'm very confused. Thank you.

3 Answers 3

1

Controllers are the logic for the data, so to login/sign-up is really validating/creating a user, if you need to view the users dash board, well that's a look up on the user data so he goes there as well.

The messages, that will be a separate controller that can create/view messages!

Sign up to request clarification or add additional context in comments.

6 Comments

The dashboard is a function? Where should I put it? Also, how can I obtain that urls with the two controllers. Thank you for your patient.
You can look into routes, but say its UserController and a method called Dashboard that needs a userKey, you would see host/User/Dashboard
This is by convention purely, you can change it in the routes. So Dashboard also returns the html (rhtml) and thats going to be your spot to spit back a UI formatted with the user data.
Controller talks to the database/Services and returns back the view, this is done by Convention also. My method is Dashboard, so my rhtml is going to be named Dashboard, and wah-lah :D.
Thank you for your tips. You suggest me to use devise for auth/signup?
|
0

As others have pointed out, your controllers contain the logic for your code and invoke views based on that logic by rendering or redirecting to pages. You can define whatever actions you want in your controllers, and then use routes to map a particular URL to a controller action. That being said, Rails gets a lot easier if you "go with the flow" and make some simple assumptions about the actions that could happen. Both your users and your messages represent rows in their respective database tables. There's no much you can do to a row in a database table - you can Create it, Read it, Update it, or Delete it (CRUD). If you define your actions in terms of these four logical actions, Rails lets you generate some easy routes.

You can back into any URL schema that you want, but what you are describing is:

  1. Read the messages that are for a user on the dashboard
  2. Create a message for a user when you go to another page (mysite/username)

Each of these maps to a CRUD action that you should be defining in your controllers.

Agreed also with other advice to simply do a few more tutorials that will probably clear this up.

Comments

0

If you haven't already, read Getting Started with Rails. Look out for the discussion on MVC and scaffolding. Playing around with scaffolding can help you learn where things go and is a great place to start for beginners.

Also, I highly recommend this book: Agile Web Development with Rails. It is very hands on and an easy read.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.