Alan Reid

Joined

55,040 Experience
459 Lessons Completed
8 Questions Solved

Activity

https://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/ interesting article about STI. Will investigate this further

ohhhh this is where it gets interesting.

Yes company and brand can be the same thing, however a company can have multiple brands haha and under those brand you could have 1 or many products in that brand line up.

Think Bacardi. Bacardi & Company Limited is the Company, Bacardi is the main brand the have for their Rum. However you also have Bacardi Breezers, which are a brand themselves.

See it can be quite confusing, which is why i thought i would make sure i was going the right way.

Cheers Chris,
Its more about getting my head around how Rails does things haha :)

Venues will have the ability to sell all products within a brand so to expand on some other actions...

Companies, who are not brands can follow brands - think twitter. So i will set up that up in a separate table. -- on the companies table i think i will need a "flag" is_brand so i can tell which is a brand or not.
Venues will sell/stock products - i assume this would be a different table.

Drawing it on paper is easier than writing it how Rails deals with it. But in reality it so much easier than other languages I've worked with haha.

Cheers again Chris, all input is a massive help.

So this site i am building goes something like this.

I need to let users log in and manage their brands, each brand belongs to a company. A company can have many users which manage this brand. The brand has many products associated with it. Now this is where things get complicated haha.

A company can have many brands, but also it could have many venues. (The venues sell the brand)

I guess what i am after is validation to make sure i am on the right path lol

Companies

  • has_many :users
  • has_many :brands
  • has_many :venues

Brands

  • belongs_to :companies
  • has_many :products

Venues

  • belongs_to :companies

Users

  • belongs_to :companies

Posted in Whats the best way to deal with JS in Rails?

In my quest to ever understand rails, i notice that Rails adds a few JS files to the bottom on my page.
Whats the best way to deal with this?

Looking at the likes of AirBNB they don't have this, so is there a way to point to JS files we need etc?

Sorry I'm not sure if i am explaining my self properly hahaha

It's all good, though, with this site I am picking up so much I am impressed with what I have made so far, and that's just the user stuff lol

cheers buddy, i will look at that. I reckon thats all i needed.

You know when you look at things for so long you just miss the obvious haha

Hi Chris,
My issue here is that I have a separate layout for the login, password reset and sign up etc. So when this errors its send me to a get on the /users page so shows my other layout haha. I need to work a way around that i think

Posted in Devise: Add a select to my signup form

Sounds cool, i will have a look see what others have written to get ideas :D Thanks

Posted in Devise: Add a select to my signup form

haha @Chris ;) That would be my first PR. I would be keen to learn how to do that on such a large scale project, for example what would need to be included etc.

Posted in How do i create another table when a user signs up?

Cheers Chris, Let me check this out and get it working :D

Posted in How do i create another table when a user signs up?

When a user signs up, i ask them for their company name so i can then associate that user with a company. How would i go about doing this? I am using devise, so somehow i will need to store the company name in the company table.

Please help :D

Posted in Devise: Add a select to my signup form

Ok, so after reading up a load about Devise, i found they have made it easy to add in parameters on to the sign up forms.

You will need to create the devise controllers so check out the devise docs for details on how to do this.

Once created open up the registrations_controller.rb and scroll down the page to around line 46. Her you will see some code which is commented out.

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_sign_up_params
#   devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end

Simply uncomment this, and add replace :attribute with the attribute you want stored to the DB! It's that easy! No need to write out your own sanitiser.

Now all thats left is to add in the fields you want added, so for me i wanted to add in a simple select, so i used the code below.
<%= f.select :is_brand, options_for_select([["I am a Brand", true], ["I am a Buyer", false]]) %>

I really hope this helps someone else out.

Posted in Devise: Add a select to my signup form

Hi all, me again! haha
So i have got my app working as i want so far. All is good and i am picking up Rails really quickly thanks to GoRails.

I am however a little stuck, I can't seem to add in a select for my sign up form.

<%= f.select :is_brand, options_for_select(%w[true false]) %> This is adding in the select, however it does not seem to store the field when i submit. I am thinking its cause its not reference by devise as standard, and i have not got any devise registration controllers.

I basically want to have a select, with a list that says...

-- Select an option
-- I am a Brand  (value would be TRUE)
-- I am a Buyer  (value would be FALSE)

Then the/false would be stored as a bool in my DB, i have the DB all set up its just getting things to store.

Thanks in advance :D

Alan

Posted in Is anyone using Rails 5 yet?

I have moved over to Rails 5 today. No issues as of yet :D Thanks all for your help

Posted in Is anyone using Rails 5 yet?

Isn't that always the case lol :) oh well i will investigate further. I am starting a large project so was tempted to start it off on the latest versions. But i am thinking it maybe best to keep it on the slightly older version.

Posted in Is anyone using Rails 5 yet?

Cool cheers Drilon, I think I will wait a little longer and let the bugs get fixed before I jump onboard. I assume its not too hard to update an app to the latest version of Rails?

Posted in Is anyone using Rails 5 yet?

The setup guides on the site recommend using Rails 4.2.6. I'm curious to know if we should be using Rails 5 now as it's been out for almost a month?

Cheers

I've declared custom routes in my app for a few of the devise actions, they are as follows:

devise_scope :user do
  get 'signup', to: 'devise/registrations#new', as: :signup
  get 'login', to: 'devise/sessions#new', as: :login
  get 'logout', to: 'devise/sessions#destroy', as: :logout
  get 'forgotten', to: 'devise/passwords#new', as: :forgotten
  get 'resend-confirmation', to: 'devise/confirmations#new', as: :resendconfirmation
end

However, when an unauthenticated user accesses a protected part of my site still gets redirected to /users/sign_in. How do I get devise to use my custom routes inside of the authenticate_user! before_action? to keep the whole experience of using my app the same.

Thanks all.