Chris Oliver

Joined

234,960 Experience
17 Lessons Completed
256 Questions Solved

Activity

Posted in Install Bootstrap with Webpack with Rails 6 Beta

A++++++

Hey Nino,

Editing requires the id of the record to be in the form so it knows which record to edit. You've got _destroy, but not id so it wouldn't know how to delete those either.. You want it as a hidden field and permitted params.

    <%= form.hidden_field :id %>

Posted in Screencast requests: Global ID and @mentions

Hey Marc!

Not sure if you missed it in the episode but thats exactly how ActionText works. It uses signed global IDs to load models and it does all that automatically for you so theres nothing you need to build.

To query, you would probably need to make an adjustment since the signed global id does not have a readable value stored in the db. May just want to add a join table between the models and add references during save.

Make sure you import Trix in your JS.

Posted in denial of service attack

I would highly recommend Cloudflare.com for DDoS protection. You'll want to set it up well before you expect to get attacked so it can protect your server IPs.

Posted in Rails credentials returning nil

I've not looked into this myself yet.

If you have scoped credentials, would you just need to access them directly without the environment since it knows which environment by the filename? Have you tried this:

Rails.application.credentials.secret_key_base

Which would load the secret_key_base from the development credentials file.

Posted in Rails credentials returning nil

Hey Nino,

Maybe this is related to Rails scoping credentials to the environment again?

Posted in User Referral Program From Scratch Discussion

Hey Ignacio,

If you look through the logs above, did it fail when installing webpacker?

Hey Joel!

I think it's because of your render method. When you render json: it's going to call the to_json method on what you pass in, not render the template.

Change that to the following and you should be fine. Basically we just want to do the query in the controller and give the variable a better name. Then Rails will know to render index.json.jbuilder when the request comes in with .json at the end.

def index
  @users = User.all
end

And accordingly, change your index.json.jbuilder file to use the @users variable to match what was set in the action.

json.array! @users do |user|

Posted in Rubu auth without gems

Hey Ivan,

I haven't covered this yet on GoRails, but I should. This is a good tutorial to follow if you want to build auth from scratch. https://medium.com/@wintermeyer/authentication-from-scratch-with-rails-5-2-92d8676f6836

Posted in Deploy Ubuntu 18.04 Bionic Beaver Discussion

Fixed, thanks Bryan! 🙏

You can definitely create a rake task for that.

What you'd need to do is decide which associated record your want your uploads with and then scan through the directory to find your files and then open then and run the attach method like so:

@message.image.attach(io: File.open('/path/to/file'), filename: 'file.pdf' , content_type: 'application/pdf')

Roughly you'd want to do something like:

Dir["/path/to/search/*.pdf"].each do |filename|
  # Look up or create record you want to attach this file to.
    # You can use the filename to parse out the customer name, etc.
  # We'll assume you set it as a variable called @record.
    @record = Record.first

    @record.image.attach(
      io: File.open(filename), 
        filename: File.basename(filename), 
        content_type: 'application/pdf'
        )
end

You would need to basically add a block to your NGINX config to take /blog and render the Wordpress app.

location /blog {
  root /home/deploy/blog;

  try_files $uri $uri/ /index.php?$args;

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php7-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Change root to point to where your Wordpress app lives and fastcgi_pass to point to your php-fpm sock file depending the version you're using.

Posted in Deploy Ubuntu 18.04 Bionic Beaver Discussion

It's saying your Postgres server isn't running, or it can't connect to it through the IP and port. Double check your connection settings and that Postgres is running.

Posted in Direct File Uploads to S3: Part 2 Discussion

It doesn't look like Roda is required anymore. You just need to include those two plugins instead of the direct_upload one.

Aside from those changes, it's probably much different. You just want your presign Javascript request to hit the presign URL and then the upload JS request needs to hit the upload_endpoint URL.

Yeah, Faraday is great, especially for making gems, that way you can easily swap out the backend library that makes the HTTP requests.

Posted in Group Chat with ActionCable: Part 3 Discussion

Like the error message says here, you're missing jQuery. Add jQuery to your app and you'll be set.

Posted in rails 5.2.2 template.rb sqlite3 versions issue

I'm hoping they release an update that fixes this soon! I've hit this a few times myself and am always surprised this is an issue. Thanks for posting the solution!

Posted in Best way to start a rails project?

I would definitely recommend using Devise for authentication for several reasons.

1) You're more likely to have security issues if you build authentication yourself
2) Devise has lots of users so they find security problems, but only hackers and yourself will be testing yours
3) Devise gets lots of updates for new versions of Rails, etc because of how many people in the community use it

I typically start with models and then create controllers. You want to have your database designed correctly before you implement your controllers. Since they are deciding how data gets saved, you need your models setup so they have somewhere to save.

Posted in Populate dropdowns based on selection with Stimulus JS

You need to have your callback using a fat arrow => instead so it keeps the scope.

      success: (data) => {
        this.message()
        this.doThingWithData(data)
      }

That will retain the scope so that this refers to the Stimulus controller. That will fix your method call error.

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.