Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Creating User Accounts & Associations

users controllers

  • Please log in to reply
4 replies to this topic

#1 SandyF

SandyF

    Passenger

  • Members
  • 4 posts

Posted 30 December 2013 - 12:44 AM

Hello! I'm a recent graduate of One Month Rails and am building my first app. 

 

In our app, a user creates storyboards that will each have a name www.oursite.com/vanityusername/storyboard1.

 

So, i gather I need to create a controller called storyboards and an index where the user can create, show, update, destroy their boards.

 

Then I create corresponding view files and a show view has containers to hold the content tiles being uploaded via various gems. I'm also guessing I need to create a model where the name of the storyboard is stored. 

 

Where I'm getting lost is in the associations .

 

Do I have this right to set up that tiles can belong to any storyboard or none? 

 

class User < ActiveRecord::Base
  has_many :tles
  has_many :storyboards
end
 
class Tile < ActiveRecord::Base
  belongs_to :user
  belongs_to :storyboard
end
 
class Storyboard < ActiveRecord::Base
  has_many :tiles
  belongs_to :user
end

 

Thanks! 

 

 

 



#2 SandyF

SandyF

    Passenger

  • Members
  • 4 posts

Posted 30 December 2013 - 01:13 AM

I can't figure out how to edit my post so forgive. 

 

Would generating a scaffold called Storyboards name:string be the right way to go? 



#3 Vasspilka

Vasspilka

    Signalman

  • Members
  • 14 posts

Posted 30 December 2013 - 01:45 PM

Hello Sandy, and wellcome.

 

It seems you can only edit your post for 10 minutes after it was written.

 

It may be becouse I haven't had my coffee yet but I don't seem to quite understand what you want to build...Could you confirm if I got things right?

 

So we have a webapp, that stores users, each user has manny Storyboards, but the Storyboard is created by only one user. The storyboard has a name (and I persume other info aswell). 

What is the tiles functionallity? And gennerally what is the Storyboard...? 

 

If you want to understand assosiations the best way would be to start here Active Record Assosiations .

However I think in your logic Routing would be really usefull aswell



#4 SandyF

SandyF

    Passenger

  • Members
  • 4 posts

Posted 30 December 2013 - 03:56 PM

Thanks Vasspilka! The app is a pinterest-like place for people to create content-rich storyboards. A storyboard is a collection of content pieces: text, image, video, audio - all pinned to a 3-column table. Each storyboard is a container (named view?), so a link can be sent to a viewer. 

 

This is an example:

http://www.pinterest.com/eclectitude/

 

Under my account, I have a set of pinboards and each board is a container of content that has been pinned to it. 

 

http://www.pinterest...le-art-jewelry/

 

Obviously, i'm still struggling with the language to describe things :) 



#5 Vasspilka

Vasspilka

    Signalman

  • Members
  • 14 posts

Posted 31 December 2013 - 10:42 AM

Aha, Sorry for not replying yesterday I was quite busy.

 

Yes, the assosiations should be fine the way you had them in your first post.

 

However I think the user does not have to be related to the tiles ( The tiles are the info inside the storyboard right?). The tiles-storyboard relation seems to be enough for the situation.

 

Overviewing the links I shared in my previous post should give you a really good insight to how assosiations work, also the Routing is how the controller makes links to obects, and how the rails app names them, so based on the things you want to make, it should be really usefull. There are guides for almost all aspects of the Rails framework in that website, so you might want to have a look there when you are stuck at something :).

 

If you want some further advise don't hesitate to ask.







Also tagged with one or more of these keywords: users, controllers

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users