Alan Reid

Joined

55,040 Experience
459 Lessons Completed
8 Questions Solved

Activity

Posted in how to move existing body content to use action text?

Of course, it seems to be working well. Saves a load of time. I sure it could be refactored to be quicker too. This was screated from a worker I am using to push updates to shopify - thus the begin, rescue, ensure

class FixProductBodyWorker
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform()
    batch_index = 1

    Product.where(x: "y")
        .find_in_batches(:batch_size => 100) do | products |

       retries = 3
       begin
         products.each do |product|
          if !product.product_body.nil?

            body_init = product.product_body

            # I added a load of editing stuff here to remove 
                        # unwanted text, or editing parts of the content.

                        # The clear out any whitespace - I do this as a lot 
                        #of the data was scraped from third-party supplier sites.
            body_edit = product.product_body.strip

            product.update(description: body_edit)
          end
         end
       rescue StandardError=>e
         puts "\tError: #{e}"
         if retries > 0
           puts "\tTrying #{retries} more times"
           retries -= 1
           sleep 20
           retry
         else
           puts "\t\tIssues processing batch #{batch_index}, so moving on"
           batch_index += 1
         end
       else
         puts "\tProceesed batch #{batch_index}."
         batch_index += 1
       ensure
         sleep 10
       end
    end
  end
end

Posted in how to move existing body content to use action text?

Quick update, made a quick worker to take my existing content, and save it to the actiontext table :D Seems to be working a treat!

Now to sit back and wait :D

Posted in how to move existing body content to use action text?

mmm, wonder if i can create a worker to do it for me basically save from :product_body to :body. I have like 32,000 records to update.

Great video though, i had it up an running in seconds! Then I sat there and went... "Oh, bugger!" hahaha

Posted in how to move existing body content to use action text?

I followed the great video Chris did on action text, however, I have an existing data structure and want to move it over to use actiontext for editing the body content.

How can i display the old content in the trix editor, if its not been moved over? Is there an easy way?

So how would you set the account_id in the URL when a user logs in? surely its not as simple as just setting Current.account = user.account_id ?

Posted in Any news on the install Rails on Catalina guide?

Currently the setup is showing how to use the bash setup, its mainly the oh-my-zsh stuff i'd like to see as im new to that.

I have set it up as much as i can so far haha :)

Posted in Any news on the install Rails on Catalina guide?

I have noticed that macOS Catalina moves to ZSH as the default shell, would be cool so get an update on the install rail guide to show this off :)

Posted in Need a hand with associations

Thanks Ivan,
A user is a user, they then need an account (for a business) which other users can be assigned to. This is where a user can be a member of an account. I understand the confusion.

later i can add in subscriptions to the mix to expand the app more.

Posted in Need a hand with associations

hi Daniel,
yeah a user can be the owner and be assigned to the account.

the updated code seems to work, but im all for finding out better ways to get things done.

Posted in Need a hand with associations

Just a quick update, after a little light reading this evening i think this maybe correct. It seems to work ok. If anyone notices something thats wrong please let me know :) thanks.

User.rb

class User < ApplicationRecord
  belongs_to :account
end

Account.rb

class Account < ApplicationRecord
  has_one :owner, class_name: :User, foreign_key: :owner_id
  has_many :users
end

Posted in Need a hand with associations

I have a users model, and an accounts model. Basically I would like to have...

  • An account has one owner
  • An account can have many users
  • Users can only be a member of one account.

Does the following look right?

User.rb

class User < ApplicationRecord
  has_many :accounts, foreign_key: :owner_id
end

Account.rb

class Account < ApplicationRecord
  belongs_to :owner, class_name: :User, foreign_key: :owner_id
  has_many :users
end

Posted in Thoughts on Rails 6, is it ready for production?

Seems like a no brainer then haha. No harm in starting a new project and just updating once it goes to stable, I will let you know how I get on.

Posted in Thoughts on Rails 6, is it ready for production?

Hey all,
So i thought i would pose the question and get other users views on Rails 6. So we are still on RC1, its been like this for a while now. I am curious to know others views, and experiences to help me work out if I should start building a new project in Rails 6 (some of the new features would be helpful).

I saw DHH said that its fine to use in production, and that Basecamp and other are using it without issue in its RC state.

Any way let me know
Alan

fingers crossed they dont mess too much, could be a decent browser. I wish Google would reduce the resources used though, still a beast of a browser.

yeah its really cool, i will look to use it on some other bits too i think. It will be a nice solution.

IE haha, I am counting the days til its axed :D I wonder how MS will mess up Chrome though haha

Yeah, I hated having it all in the form so start to mess around. I found the button_tag element could be attached to a form essentially so i can put the button anywhere on the page. It was just this edit issue i had which stumpped me haha.

So happy to get it all working now :D can finish this app off and move on to the next version :D

yeah I set the form using form: 'edit_product_' + params[:id] cheers as always mate :D

Yeah its outside the form tag.
You made me look at it again, and the form is using the ID of the item!

So doing the following fixes the issue!

<%= button_tag("Create", type: "submit", form: 'edit_product_3') %>

If you put the images in your app/assets/images directory, then you should be able to call the image directly with no prefix in the path. ie. image_url('logo.png')

I am using the following to submit my form when creating a product.

<%= button_tag("Create", type: "submit", form: 'new_product') %>

However, the issue I am facing is that when I try to do the same for editing a product, the form does not submit at all.

<%= button_tag("Create", type: "submit", form: 'edit_product') %>

My question is, what am I missing from this not to submit the edit form? I mean when I press the button, nothing happens at all. haha

I know there's bound to be simple answer thanks in advance