Alan Reid


51,070 Experience
419 Lessons Completed
8 Questions Solved


Posted in What is your dream app?

Yelp-like app to help people find mental health resources sounds like a good idea Shakycode

I am working on

  • Drinks portal (with Jacob)
  • Pixel Tracking app, basically an analytics app which will allow the tracking of product purchases.
  • Not rails, but i am building a Jekyll blog for movie reivews. Actually it is kinda Rails related ;)

Posted in Prevent spam bots from hitting app

I agree with Jacob, sign up for a free cloudflare account, they can help prevent things like this happening. I use cloudflare for all my DNS needs, there are many additonal features for too such as caching and SSL.

Posted in Devise User Follow System

Michael Hartl does a video Tutorial via the Learn Enough site, you need to subscribe though. It's good but its everything thats in the book.

I would suggest using something like "Chosen" and populating it using Rails. - simple jQuery plugin which may be useful.

Populate similar to this...

<%= f.collection_select :product, @products.all, :id, :name, { class: 'chosen-select'} %>

I have used this a couple of times now and it works great, plus users can search for items. But it also depends on how you layout your form, remember to make sure its user friendly and you're not overdoing the form.

Posted in Setup MacOS 10.11 El Capitan Discussion

Hey Jesica :) thanks. I found these instructions worked a litter easier

Enter the following in your terminal window

$ touch ~/.bash_profile; open ~/.bash_profile

In the text editor window that opens add the following code:
which rbenv > /dev/null; then eval "$(rbenv init -)"

Saved your .bash_profile

Posted in How do I submit multiple checked items?

Sorry was just testing something out :)

Posted in How do I submit multiple checked items?

Sounds like a plan Jacob, i could do with someone with expertise in Rails helping me out haha feel free to drop me an email

Posted in How do I submit multiple checked items?

Mate that last one worked perfectly! Just need to do some checks to make sure there are items in the params and then redirect if the save is completed.

I personally prefer your method, it makes more sense to me. Thanks again, maybe i need to get you involved in this project too haha.

Posted in How do I submit multiple checked items?

In regards to the code you gave, it works up to the save, where i get the following error...

#<NoMethodError: undefined methodsave!' for #Class:0x007fbac0e53288>`

Thats just for when i save 1 item. When i add in multiple it duplicates the entries

Posted in How do I submit multiple checked items?

So i have spoken to a couple of people and have had this suggestion...

In the back_bar.rb model...

  def self.add_set(vanue_ids, product_id, variant_ids)
    values ={|ven|{|var|
        "(#{ven},#{product_id}, #{var})"

    ActiveRecord::Base.connection.execute("INSERT INTO back_bars (venue_id, product_id, product_variant_id) VALUES #{values}")

Which means i can now use this in my controller...

  def create
    if BackBar.add_set(params[:venue_ids], params[:product_id], params[:variant_ids])
      flash[:success] = "Product has been added to the selected back bars."
      # Redirect to the back bar page
      redirect_to back_bars_path
      flash[:alert] = "A selected variant for is already in your back bar."
       # Redirect to the product page
      redirect_to discoveries_product_path(params[:product_id])

This is pretty interesting and similar to how you and Chris said to do the articles stuff a few threads back.

My only issue is validation, how would i validate that the params are valid so i can move on with the save. Or would you say your way is the way to go?

Posted in How do I submit multiple checked items?

Hey Brittany, Thanks but that looks to just be relating to the front end but very handy :)

Jacob, that kind of works, however as it works through the venues its simply overwriting the previous one. lol :)

Posted in How do I submit multiple checked items?

Awesome, thanks. I'll give it a try in the morning. And see what i can get working.

Finally got my Rails books here so i can start reading up and learning more haha

Just got Agile web development with rails 5. I heard good things so fingers crossed i pick up a fee things haha

Posted in How do I submit multiple checked items?

Yeah, so a separate row per products variant associated to a venue. It seems to work, but its the save part which messes up so i think i need to move it out of the loops haha

i like the idea of a mass save, so thats basically creating an object and saving?

Posted in Use .ENV instead of Secrets.yml for keys

Obviously make sure you don't commit your 'secrets.yml' file to any publicly accessible repo if it contains sensitive data ;)

i personally used Chris's shrine video and stored images and files locally when in development. Then put my S3 credentials in Heroku's settings so my production site uses S3. Yeah its manual but least i know they are only in one place.

Posted in How do I submit multiple checked items?

Cheers buddy, yeah i did a google and came across the videos you mention. They didn't really cover what i was trying to do. Most of them store the array within a string field in the DB. I want to create a new row for each venue and variant.


venue_ids => ["1","2"], variant_ids=>["10"]

So i would want to add in a row which has a venue_id of 1, with variant_id of 10. And a venue_id of 2, with variant_id of 10

I got this kind of working and its now passing in my 2 arrays. I think I am almost there i am not sure the .each is the right way to do it but i think i am on the right track haha. So i have it submitting however where would i put my cause this might cause issues as it wont redirect

@back_bar =
@venues = params[:venue_ids]
@variants = params[:variant_ids]

# For each venue we have in the array, grab the ID.
@venues.each do |v|
  @back_bar.venue_id = v

  # Then for each variant we associate the variant ID with that venue.
  @variants.each do |pv|
    @back_bar.product_variant_id = pv

    # Add in our product_id
    @back_bar.product_id = params[:product_id]

    # Save the venue and variant to the DB.
      # Redirect to the back bar page
      redirect_to back_bars_path
      # Redirect to the product page
      redirect_to discoveries_product_path(@back_bar.product_id)


  def back_bar_params
    params.require(:back_bar).permit(:venue_id, :product_id,  :product_variant_id)

Posted in How do I submit multiple checked items?

Hi all,
can someone guide me in the right direction please?

Basically i have dynamic options a user can select 1 or many of these items. I thought checkboxes would be good for this.

The user then submits the form and an array is then passed over and a separate row for each selected item is added to the Db


I have my DB already set up, and it references another table. I need to add in :unique => true so i don't get duplicates. I cant however drop the table and start over as there are items in the DB already.

I know i could do this if i wanted to add a column in to the DB, but what about when it already exists?

rails generate migration add_column_name_to_table_name column_name:references:uniq:index

Which would generate...

class AddIndexToModerators < ActiveRecord::Migration
  def change
    add_reference :table_names, :column_name, index: {:unique=>true}, foreign_key: true

Posted in Pull data from another table in a lookup

might need to look at the subscriber times in the diamond, mine says 3 months but i done 4 payments?

Posted in Pull data from another table in a lookup

@chris you made more than just that change i see. looks good mate

Posted in Pull data from another table in a lookup

Yeah naming always is a pain, to me it made sense but I understand your points. ;) will fix in v2 of the app haha what I'm building ATM is still very my a proof of concept to show the idea will work and get people on board

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.