Alan Reid

Joined

38,810 Experience
304 Lessons Completed
7 Questions Solved

Activity

Posted in RuntimeError (can't modify frozen String)

What should add_breadcrumb 'category / ' << @title, categories_path output?

Posted in RuntimeError (can't modify frozen String)

Hi all,
I have user groups setup on my app using the code below...

class User < ActiveRecord::Base
  has_many :user_groups
  has_many :groups, through: :user_groups
end

class Group < ActiveRecord::Base
  has_many :user_groups
  has_many :users, through: :user_groups
end

class UserGroup < ActiveRecord::Base
  belongs_to :user
  belongs_to :group
end

All is working as expected, users are assigned to a group, and can access the data for that group. I have come accross an issue where any user, can access ANY group. Obvioulsy this is not good haha.

Can anyone recommend how i would go about preventing access to a group if a user is not a member of the group they are trying to access.

I was thinking of using a before_action and using it there and other controllers when needed.

FYI, i also have products assigned to groups so have a URL structure (below) which measn the ID variable for the group changes, not sure if i could just make that stay as :group_id maybe?

/groups/{:id}
/groups/{:group_id/products
/groups/{:group_id/products/{:id}

Any help would be much appreciated. Thanks in advance.
Alan

Posted in Load only products based on region ideas please :)

Yeah this is what i was thinking. Cookies were my preffered way, it also means i can keep the url simple.

Thanks as always Jacob. Its good to get feedback on the ideas in my mind :)

Posted in Load only products based on region ideas please :)

Hi all,
Im trying to work out the best way to do a task.

On the users menu, they are able to select a region they are a member of. Once a user selects a region I want to load all data on the page based on that data until they select another, or reset it to all.

So if a user has not selected an option they will see all data for the regions they are a member of.

I have a couple of ideas, but is there a better way to do this?

Idea 1: have a :region_id in the URL - if none loads all. Other wise have a route like

  • site.com/region/overview
  • site.com/region/products
  • site.com/region/:region_id/overview
  • site.com/region/:region_id/products

Idea 2: Set a cookie, and load based on that?

Yeah, this is something I will have to look into in more detail.  I am new to the whole scraping of sites, but it's been a really cool learning experience and I am much more confident.

I did have a look at the import gem, and I am sure moving forward I can refactor the code better for scrapes.

This was an interesting post - https://blog.codeship.com/speeding-up-bulk-imports-in-rails/
It works perfectly. Just not a fan of the looping but it's a background task after all.

It will totally depend on the site, this one I am pulling in a global hit of 152, others may have less. Really enjoying Nokogiri and Sidekiq
Hey Jacob, 
Been a while!! :)

I have just been trying something similar, I did start to look at transactions. I think the main issue is that I am creating an array of items to insert. And as this is within sidekiq I am having to use plain ruby. 
Hi all,
I am creating new records, and want to be able to catch the ones that error and add them to my activity log so I can look into them and why they may have failed.

What would be the best way to do this?

Currently, I am doing the following by passing over an array of categories.

Category.create(categories)

I have validation on the name of the category to make sure its unique.

I would like to see which ones have failed and also have a total count of which ones were created vs failed. For example...

  • xyz failed to be created.
  • Created 99/100 categories, 1 failed.

I am using a simple activity log which I have made myself. And would like to have these details stored in the "log_msg"

ActivityLog.create(:act_type => "Insert", :act_action => "", :updated_by => "System", :activity => log_msg, :act_tstamp => Time.now)


Posted in Can anyone suggest me best Ruby on Rails 5 book?

I third The Ruby on Rails Tutorial, fantastic book! You can even follow it online at - https://www.railstutorial.org
But the book is also well worth buying for reference.

I also found Rails: Novice to Ninja quite good - https://www.sitepoint.com/premium/books/rails-novice-to-ninja

Also, check packt publishing and their free ebooks - https://www.packtpub.com/packt/offers/free-learning - they covers many different languages.

Posted in Update an attribute on belongs_to

Ok i seemed to have got it to work as i wanted, thanks for the guidance Chris :D

Posted in Update an attribute on belongs_to

I think the second option maybe quickest, for now, I can always go back and refactor the code to improve it later.  At present, I just need to be able to assign a `produduct_group` to a product and let it be updated when editing the product.

How would I go about doing this?

Posted in How do I generate dynamic classes?

I did something like this when I was working out the column widths once, maybe you could do similar.

$grid-columns : 16 !default;
$grid-gutter : 0% !default;
$column-width : 100 / $grid-columns;

// Lets calculate the column widths, outputs in %'s
@function grid-column-width($n) {
@return $column-width * $n - ($grid-gutter*($grid-columns - $n)/$grid-columns);
}

@for $n from 1 through $grid-columns {
%col-#{$n} {
width: grid-column-width($n);
}
}

Posted in Update an attribute on belongs_to

Hi all,
I have my products and groups set up like so...

class Product < ApplicationRecord
  has_many :product_groups
  has_many :groups, through: :product_groups
end

class Group < ApplicationRecord
  has_many :product_groups
  has_many :products, through: :product_groups
end


class ProductGroup < ApplicationRecord
  belongs_to :product
  belongs_to :group
end

Basically, a product belongs to a group. All seems to work well.

Now I have a form which is updating the product attributes perfectly well. However, how would I go about updating the group the product is in? I have tried to Google this, but there doesn't seem to be anything which helps.

All help would be much appreciated, thanks.

Had an interesting message from a GoRails member (Jacob) which mentioned what music we listen to as we develop. It's a great discussion starter and could be cool to share playlists from Spotify, or tracks that really help you get int he zone as you're building up your apps.

We could even create a GoRails Spotify playlist. And if you don't use Spotify what do you use?

So to get us started, I have been listening to these acoustic playlists they get updated every so often. But I find them great to have playing in the background. 

Hot Acoustic Covers and Acoustic Cafe Mornings

Posted in Lots of trouble using LESS in a paid theme.

You could take a look at this site - http://less2scss.awk5.com

Depends how complex it is, cause it's quite easy to convert manually.

Posted in How do I create a Zapier integration with a rails app?

I have messed with Zaps in my previous job, and had a form submitting via Zapier into a Google Sheet.

Hopefully this Medium article can help?

https://medium.com/@ThatGuyTinus/rails-to-anything-integrating-zapier-via-webhooks-3e51a8f6a54f

Have you taken a look at Devise Roles? It will make your life a lot easier this way.

https://github.com/plataformatec/devise/wiki/How-To:-Add-a-default-role-to-a-User

Posted in What are your goals for 2017?

Hi Riya,
What you like to know about my Pi project?

You are definitely in the right place to learn Rails :) - Chris provides and excellent resource here.

Posted in Saas-Mixins

could you post a code sample?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.