Activity
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
Posted in Creating an application Multi Language
Hey Kelvin,
I'm not too familiar with it, but you might try this gem: https://github.com/globalize/globalize
It can help you on the ActiveRecord model side to handle languages using a translations table it looks like.
Thomas, the Stripe series is new a separate course from GoRails: https://courses.gorails.com/payments-with-rails-master-class
It covers the latest Stripe with a shopping cart example for one-time payments, Stripe Billing subscriptions. Soon it will have Braintree + PayPal examples in the course as well.
You would probably need a multitenant plugin for Spree to do that.
Looks like there are a few gems for this:
https://github.com/spree-contrib/spree-multi-domain
https://github.com/spree-contrib/spree_shared
I haven't used Spree in years, so hopefully that helps point you in the right direction!
One thing to note: you would use Puma OR Passenger, but not both. Apache can proxy requests over to Puma, or you can have it send requests to Passenger. It's definitely easier to use Passenger because you don't have to have another process running.
Rails comes with Puma by default now to support web sockets in development, and you could also run Puma in production, but you have to run it as a separate background process with SystemD.
If you're using Passenger, you don't need to do that and you can just define the Server in Apache to have it load it.
When you say you have no problem connecting when using Puma, do you mean by running "rails console"?
Also can you share the full stacktrace for your error?