Activity
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?
Hey Ignacio,
If you look through the logs above, did it fail when installing webpacker?
Posted in jbuilder serializer for returning INDEX endpoint not working like it did with me.json.jbuilder ....
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
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.
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.
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.
Like the error message says here, you're missing jQuery. Add jQuery to your app and you'll be set.
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.
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.
Posted in Why have the three dots syntax?
The triple dots are called the object spread operator. Basically it allows you to expand variables in useful ways to simplify the code you're writing. Here's a couple articles about it:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
https://medium.com/@oprearocks/what-do-the-three-dots-mean-in-javascript-bc5749439c9a