karatepicke

Joined

3,450 Experience
26 Lessons Completed
1 Question Solved

Activity

Posted in Tracking online users with timestamps Discussion

I was thinking about that particular question as well, as I watched the episode yesterday. Could someone elaborate?

Hey!

I guess you'll need to provide some code, in order for us to be able to help you :)
Things to look out for:

  • has your "update"-button the correct path/link specified?
  • does your route call the desired controller action?
  • is the HTTP-verb correct? (watch out for method: :delete on your button specifically)

Cheers,
Dom

Posted in Create Customer Url

Hey Suleiman,

something along those lines should work:

routes.rb

get "/:user_account_number/projects/:project_id", to: "projects#show"
# pay attention to the colons (:) within the url here. It signals to Rails that these are variable parts ("params") which can change.

projects_controller.rb

class ProjectsController < ApplicationController
  def show
    user = User.find_by(user_account_number: params[:user_account_number])

    if user.present?
      @project = user.projects.find(params[:project_id])
    else
      flash[:alert] = "No project found with ID: #{params[:project_id]}"
    end
  end
end

Regards,
Dom

Hey guys,

I just started a project (based off of Jumpstart Pro). One of its core features should be a price comparison: I'd like the app to fetch prices across different websites/webshops several times a day and display those prices in an aggregated way on the respective product's show page.

How would you go about designing this? At my current stage I lack the experience to make this design choice all by myself - I definitely want to find the optimal solution, right from the start.

Aspects I am interested in hearing your opinions about are:

  • DB design: new model for scraped prices with an association to the product itself? Or just store an array of prices on the product? Etc.
  • Worker for the price scraping? (Unfortunately I cannot rely on the existence of APIs to simply request prices from)
    • this is totally new to me. What worker should I use?
    • it should be fairly to maintain and debug
    • optimally, it should be scalable and easy on computing resources
  • Error handling:
    • how to handle (temporarily) inaccessible websites
    • how to maintain a "low profile" and prevent being blocked from fetching a website's information

Thanks in advance for any insight on this!

Posted in How do I learn to write dry code?

In Order to become an overall better software developer, I recommend you read "Clean Code" by Robert C. Martin. I have been developing software for a little more than 2 years now and this book has helped me better understanding what makes good code. Though, if I remember correctly, the code examples are presented in Java, I think you'll get the hang of it just fine.

As for your code example: the overarching pattern seems to be that you export .csv-files in all of these export-controller-methods. You could think about creating some sort of helper-method / controller-concern to which you can pass the data to be exported and the desired output-filename.

def export_csv(data, filename)
  # return unless data.any? you could put a guard-clause here, to prevent passing empty data to the export

  send_data data.to_csv, filename: "#{filename}.csv"
end

You could then do:

def export_tips
  @appointments = Appointment.order('service_id')
  export_csv(@appointments, 'tips')
end

def export_pets
  @clients = Client.all
  export_csv(@clients , 'pets')
end

Posted in Running only a part of a huge (2000+) specs suite

In addition to what Axel wrote earlier, you could also add a focus-tag to specific cases, should you only want to test them individually. It works like so:

# specs/discount_checkout_spec.rb
it "should checkout with discount", focus: true  do
    # some test code here
end

Posted in Ask password after confirmation (devise)

Hey Brijesh,

as far as I can tell from your source code, you'll likely need to adjust your do_confirm-method within your confirmations_controller.rb.
Take a look at line 65 where its says "sign_in_and_redirect". Therein should lie your solution, once you changed this, to not sign the user in automatically and redirect him to your sign_in-view instead.

Posted in Github actions & RAILS_MASTER_KEY

Hey Chris, hey community,

I've been following along your guide on setting up GitHub-actions with Rails (https://gorails.com/episodes/github-actions-continuous-integration-ruby-on-rails), however I'm facing an issue in one of the last steps, namely "# Build and run tests":

rails aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/runner/work/my-project/my-project/config/environment.rb:5:in `<main>'
/home/runner/work/my-project/my-project/bin/rails:9:in `<top (required)>'
/home/runner/work/my-project/my-project/bin/spring:15:in `require'
/home/runner/work/my-project/my-project/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
ArgumentError: key must be 16 bytes

I am inferring that this has to do with my RAILS_MASTER_KEY-variable.

I double-checked the key which I stored in my project's ENV-variables and it happens to be 32 bytes. I am unsure about how to best proceed and I am hesitant to delete the key, in order to create a new one. Setting an option for the key to be legal with 32 bytes would be much preferable in my book - it's just that I wouldn't know how and where...

Any thoughts on how to solve this issue?

Thanks in advance,
Dominik

logo Created with Sketch.

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.