Tom Dringer

Joined

1,580 Experience
4 Lessons Completed
1 Question Solved

Activity

Hi, I am having to use a different computer whilst mine is in for repair. So i generated the SSH keys to be used for deployment with Hatchbox. Using [email protected] or [email protected] just gives me an error Permission denied (publickey). Does anyone know a fix for this? I am locked out of my server and i desperately need to check the logs for an error which is giving me a white screen of death. Thanks

Posted in Space Upgrades - A browser game made in Rails

Wow thats awesome!

Posted in Order by score using Pagy pagination?

@joshBrody - just check default scope is only going to be in the model or the controller i guess?

Posted in Order by score using Pagy pagination?

I've just checked and i don't have default scope anywhere

Posted in Order by score using Pagy pagination?

Hi everyone. I am currently trying to order some ActiveRecord records by score. In my controller i have:

def index
    @pagy, @drivers = pagy(
        Driver.select(
            'drivers.*',
            '(drivers.no_races + drivers.no_poles + drivers.no_podiums + drivers.no_wins) AS score'
        ).reorder('drivers.score DESC'),
        page: params[:page],
        items: 16
    )
  end

I am using Pagy for the pagination. As the code shows, I do a query to select all drivers and then add together 3 columns in the table as 'score'. I then want to order by score going from high to low and show 16 records per page.
When the page loads it seems to order by driver id. I can't see anywhere else that i have an order by, but i did add reorder to override anything else.
Anyway for whatever reason i'm stuck with the wrong ordering. Any direction is appreciated :-)

Mockup - http://29qg.hatchboxapp.com/drivers

Posted in Hatchbox deployment. public/index.html not found

Ok i made a staging enviroment in my app, which i guess could be the issue. I have environment variables on Hatchbox using staging, rather than p[roduction. I'll dig deeper. Thanks

Posted in Hatchbox deployment. public/index.html not found

Cool can i set this somewhere? My path should be pretty default. Its just app/

Posted in Hatchbox deployment. public/index.html not found

Hi,

I am deploying to hatchbox and everything appears fine until i load the site up in the browser. Looking at the logs there is no public/index.html. On my development environment there is also no index file in public. I am using Rails 6 which apparently doesn't build a public index.html file?

Posted in Postgres issues

I now have Postgres running on my local machine nicely. My issue now is i can't run a migration due to the following error:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "drivers" does not exist
LINE 8: WHERE a.attrelid = '"drivers"'::regclass

There should be a relationship between a user and a driver, where the user has one driver.

In my user (Devise) model I have has_one :driver

and in my driver migration I have:

t.string :user_id
t.belongs_to :user

So in the driver table the user_id field should hold the user.id.

Any direction is appreciated.

Posted in Postgres issues

Hi,

So as i began a project earlier in the year, i decided to go full Docker for deployment. That was all good except debugging and stuff proved difficult so this weekend i decided to make the project native and use something for deployment.
Long story short, now i have gone back to a native based project (i.e no Docker), my Postgres installation (which was fine in the beginning) now just does not work.
I had issues with port numbers (which i have since managed to fix) and no issues with database not found. To make things worse, i think (i'm on macos and using Rubymine) i have Postgres installed via the OS, multiple versions by Homebrew, and some from standalone Postgres apps.
So obviously with these issues, i can;t start my app or run migrations etc.

Has anyone had this issue when moving away from Docker?

My error at the moment is no database named "xxx". I thought when i did i migration its all taken from the database.yml? I've run commands like rake db:create and similar.

I'm not totally sure the db i am connected to is even the right one.

Posted in Pretty urls with FriendlyID Discussion

Is it possible to to make the url "{id}-{user.fname}-{user.lname}"? It seems to work fine clicking on links, but as soon as i try to create, edit, or delete anything i get route not found.

Hi,

I want to validate my image upload field by making a user upload only a square image (i.e 200px x 200px). I'm basically wanting square image dimentions so it will resize and nicely and not look disproportional. Can this be done? Thanks

Posted in Share resources among controllers?

Anyone interested in this, in the news controller under def index you can just add the variable @students = Students.all or whatever and it really is as simple as that.

Posted in Share resources among controllers?

I'm thinking i need to look at Nested Resources?

Posted in Share resources among controllers?

Hi,

I’m not even sure I’m using the correct terminology here (sharing resources among controllers) but here goes.
Imagine I have a page called students with the usual CRUD functionality and another page with another controller called news or something. If the student page had a table called students with first name, second name etc ... how would I use the student table in the news template so I could do a for each student to list names or whatever? This is where things start to fall apart in my understanding of Rails. Thanks!

Posted in Liking Posts Discussion

I am also having the 404 issue but it's something to do with routes i'm guessing?

ActionController::RoutingError (uninitialized constant Developments):

and then in the console:

POST http://localhost:3000/developments/1/like [HTTP/1.1 404 Not Found 1343ms]

When i run rake routes I get the following:

new_development_like GET /developments/:development_id/like/new(.:format) developments/likes#new

edit_development_like GET /developments/:development_id/like/edit(.:format) developments/likes#edit

development_like GET /developments/:development_id/like(.:format) developments/likes#show

PATCH /developments/:development_id/like(.:format) developments/likes#update
PUT /developments/:development_id/like(.:format) developments/likes#update
DELETE /developments/:development_id/like(.:format) developments/likes#destroy
POST /developments/:development_id/like(.:format) developments/likes#create

Any feedback is appreciated. Thanks!

Posted in Adding Javascript to Rails 6

Wow that really is above and beyond! Thank you so much!

Posted in Adding Javascript to Rails 6

Thanks for the feedback. I get the same error still, but this time much more detailed.


Uncaught ReferenceError: toastr is not defined
<anonymous> (index):38
dispatch turbolinks.js:75
notifyApplicationAfterPageLoad turbolinks.js:994
pageLoaded turbolinks.js:948
e turbolinks.js:872
start turbolinks.js:882
start turbolinks.js:1040
<anonymous> application.js:24
<anonymous> application-51d3c38d384dcac9fb08.js:2
Webpack 3
localhost:3000:38:5
<anonymous> (index):38
dispatch turbolinks.js:75
notifyApplicationAfterPageLoad turbolinks.js:994
pageLoaded turbolinks.js:948
e turbolinks.js:872
(Async: EventListener.handleEvent)
start turbolinks.js:882
start turbolinks.js:1040
<anonymous> application.js:24
<anonymous> application-51d3c38d384dcac9fb08.js:2

I have cleared my cache and all the usual things. Is there anything i should be looking out for in those errors?

I load my js in the head tag on my application layout file<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

Thanks

Posted in Adding Javascript to Rails 6

Sure, so for example. I am trying to add Toastr. I have installed via Yarn.

In my javascript/packs/application.js I have require("toastr")

I also have an application_helper.rb which i saw from a tutorial about adding Toastr so i have:

def toastr_flash
    flash.each_with_object([]) do |(type, message), flash_messages|
      type = 'success' if type == 'notice'
      type = 'error' if type == 'alert'
      text = "<script>toastr.#{type}('#{message}', '', { closeButton: true, progressBar: true })</script>"
      flash_messages << text.html_safe if message
    end.join("\n").html_safe
  end

Then I call toastr_flash in my views/layouts/application.html.rb.

The error i get is Uncaught ReferenceError: toastr is not defined

Any direction is appreciated.

Posted in Adding Javascript to Rails 6

Hi. I am fairly new to Rails and so far I have been unsucessful at adding any JS to my Rails 6 project. I have seen many videos and tutorials but i seem to run in to the same issue. Basically I get "xxx is undefined" for every script. I'm thinking my scripts are called at the wrong time or in the wrong order. I'm using Webpacker for my JS. Thanks

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

© 2020 GoRails, LLC. All rights reserved.