Alan Reid

Joined

55,040 Experience
459 Lessons Completed
8 Questions Solved

Activity

I would suggest using something like "Chosen" and populating it using Rails.

https://harvesthq.github.io/chosen/ - 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:
if
which rbenv > /dev/null; then eval "$(rbenv init -)"
fi

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 = vanue_ids.map{|ven|
      variant_ids.map{|var|
        "(#{ven},#{product_id}, #{var})"
      }
    }.flatten.join(",")

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

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
    else
      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])
    end
  end

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.

Example:

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 @back_bar.save? cause this might cause issues as it wont redirect

@back_bar = BackBar.new
@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.
    if @back_bar.save
      # Redirect to the back bar page
      redirect_to back_bars_path
    else
      # Redirect to the product page
      redirect_to discoveries_product_path(@back_bar.product_id)
    end 
  end
end

private

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

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

cheers

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
  end
end

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

Posted in Pull data from another table in a lookup

I will go stand in the corner for an hour and hang my head in shame due to my poor naming conventions,

Seriously though cheers guys, and yeah please do some more episodes on Data and this stuff haha

Posted in Pull data from another table in a lookup

That worked!! mmm ok i really need to consider my naming of tables in the future i think. Or make it clearer that a table is a join table haha

Thanks again Chris and Jacob for all your help!!

Posted in Pull data from another table in a lookup

The join table you mention Chris is the back_bar. Maybe I should have called it something else like venue_products i was just trying to keep it with the terminology used in the app :)