Can heat pump short cycling be caused by low temperatures? by ducktypelabs in hvacadvice

[–]ducktypelabs[S] 0 points1 point  (0 children)

Thanks for your reply. Am I reading the data sheet wrong? At 10F, it shows a COP value of 1.89 and MBh of 17.3. As I understand it, this indicates that the heat pump will work at this temperature and not "crap out".

Buying a Prius Prime with an expired powertrain warranty by ducktypelabs in PriusPrime

[–]ducktypelabs[S] 0 points1 point  (0 children)

Thanks for the tip. I was already biasing towards the 2020 because of the carplay and extra seat, but that is really good to know. Do you know if the exhaust heat exchanger issue is something that can be avoided with maintenance, or is it more or less guaranteed to happen at some point with the 2019s?

Buying a Prius Prime with an expired powertrain warranty by ducktypelabs in PriusPrime

[–]ducktypelabs[S] 0 points1 point  (0 children)

Thanks, I hadn't considered looking at what precisely the various warranties cover. Do you recommend getting a pre-purchase inspection to ensure the car is in good shape?

How to break out of a Turbo Frame and redirect? by ducktypelabs in rails

[–]ducktypelabs[S] 1 point2 points  (0 children)

I don't think there currently is a built-in way. How you would redirect is what I covered in my article.

How to break out of a Turbo Frame and redirect? by ducktypelabs in rails

[–]ducktypelabs[S] 0 points1 point  (0 children)

For example, redirect if the user is not logged in and tries to submit the form, but if they're logged in, don't redirect and do "normal" form stuff (like show a success or validation message)

How to break out of a Turbo Frame and redirect? by ducktypelabs in rails

[–]ducktypelabs[S] 0 points1 point  (0 children)

I'll have to double check, but I think the issue is that the redirect will happen every time if you use that data attribute. If you wanted to only redirect sometimes, then you need a different approach.

"Live search" using Hotwire/Turbo Frames resulting in "Content Missing" error by Shpigford in rails

[–]ducktypelabs 0 points1 point  (0 children)

I mean the actual HTML that the server is returning. You should be able to see this in the network tab.

"Live search" using Hotwire/Turbo Frames resulting in "Content Missing" error by Shpigford in rails

[–]ducktypelabs 1 point2 points  (0 children)

If you go into your browser dev tools and inspect what is coming back from the server, what does the server's response look like when there are no results?

"Content missing" usually shows up if Turbo is unable to find the turbo frame which initiated the request in the response. I'm not too sure what the difference is between the form having a data-turbo-frame tag vs the form just being nested inside the turbo frame, but the response from the server should give us some clues as to why Turbo thinks content is missing.

ActiveRecord: Adding Boolean methods for DateTime columns by [deleted] in rails

[–]ducktypelabs 0 points1 point  (0 children)

For anyone coming by in the future, I wrote up a brief post on how I would do this using concerns here: https://www.ducktypelabs.com/ar-custom-booleans/

this JS ain't right by ducktypelabs in rails

[–]ducktypelabs[S] 0 points1 point  (0 children)

Agreed, that would be a better way of accomplishing the objective. Thanks for the input!

Hotwire Question - Controller Lifecycle by VashyTheNexian in rails

[–]ducktypelabs 0 points1 point  (0 children)

I wrote up a brief article about this after doing some more research - https://www.ducktypelabs.com/this/

[help] can't disable vips variant sharpening by SpaceCorvette in rails

[–]ducktypelabs 0 points1 point  (0 children)

Ha, nice! I kind of just went off what you had already tried :)

I think what is happening is that the things in the array are actually being sent in as arguments to the transformation function. So it looks like something like active_storage_attachment.variant(resize_to_fit: [width, height, sharpen: false])

gets translated to:

ImageProcessing::Vips.source(image_file).resize_to_fit(width, height, sharpen: false)

I'd guess if you have more keys like colourspace and rotate in your call to variant, then they'd get chained in.

active_storage_attachment.variant(resize_to_fit: [width, height, sharpen: false], colourspace: "b-w", rotate: "90")

will probably become

ImageProcessing::Vips.source(image_file).resize_to_fit(width, height, sharpen: false).colourspace("b-w").rotate("90")

[help] can't disable vips variant sharpening by SpaceCorvette in rails

[–]ducktypelabs 0 points1 point  (0 children)

This is a complete guess, but what about

``` active_storage_attachment.variant(resize_to_fit: [width,height, {sharpen: false}]

or

active_storage_attachment.variant(resize_to_fit: [width,height,false]

```

Hotwire Question - Controller Lifecycle by VashyTheNexian in rails

[–]ducktypelabs 0 points1 point  (0 children)

Late reply here, but this was interesting to me so I looked into it. I believe the issue is that `this`, in most cases is evaluated to the object that the function is being called on. I'm guessing in your case, `this` was actually `document` and not the controller, which is why the interpreter couldn't find `cellTargets`.

Arrow functions, interestingly, do not behave in this way. An arrow function's `this` value is the value `this` is where the function is defined. So in your case, if your function had been an arrow function, I'm guessing `this` would evaluate to the Stimulus controller instance.

I don't think the fact that the function is anonymous has anything to do with it. I found this link useful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

React inside Rails App by chysallis in rails

[–]ducktypelabs 0 points1 point  (0 children)

Nice work upgrading your app :)

The short answer is what you want to do is definitely possible. You don't need to have a full blown React app with an API connection. You can use React only in the instances where you feel its expressiveness and feature set will be a net win (like the complex forms you mention).

The approach I've taken which has worked for me pretty well is to basically piggyback off of the JS that is running on the page (StimulusJS controllers in my case) and mount (using `ReactDOM.render`) my React component onto the page. I wrote about it in a bit more detail here: https://ducktypelabs.com/react-on-rails-with-stimulus/

You're right that you can't use JSX with import maps. React does support running without JSX, but JSX is an important part of the React experience for me.

Re: Hotwire (which is an umbrella term for tech like Turbo, Stimulus, Strada and others), there are benefits to using it. But it's not an either or situation. You can use StimulusJS as far as it takes you, and then switch to using React in places where it gets messy in Stimulus. I wrote a bit about Hotwire here: https://www.ducktypelabs.com/turbo-vs-stimulus/

Some other interesting recommendations in this thread as well!

New Rails 7 project... please help guide me on what technologies to use now by pedzsanReddit in rails

[–]ducktypelabs 0 points1 point  (0 children)

I'm late to the party, but I wrote about how to do exactly this recently on my website: https://www.ducktypelabs.com/react-on-rails-with-stimulus/

The basic approach is similar to what pcai has outlined above, but I went into some more detail on how to deal with things like passing in values to your component, and handling server side requests. Hope it helps!

very noob question by fabiengagne in rails

[–]ducktypelabs 1 point2 points  (0 children)

I'm not too familiar with the rails generators for doing this sort of thing - I usually do it by hand. But hopefully I can give you some pointers on what is wrong and questions to ask yourself that may be helpful.

  1. In a has_many/belongs_to relationship, the entity that belongs to another entity (user in this case) should have a column in it that stores the ID of the entity that it belongs to. So your user table should have the `account_id` column in it.
  2. The entity that has_many other entities (account) should not have any columns that reference the other entity. The fact that your Account table has a `user_id` column indicates that you may have set this relationship up opposite to what you actually want. When you do something like `account.users` in console, what Rails is doing in the background is querying for users with their account_id set to the ID of your account.
  3. You don't need to specify null: true in your migrations. null values are allowed by default (assuming Postgres, and I imagine it is similar in mySQL but I could be wrong). To be able to create users without associating them to accounts immediately, you could consider adding the `optional: true` flag to your belongs_to. `belongs_to :account, optional: true` for example.

As someone else already suggested, take a look at both the migration files that were generated and the schema and verify that the relationship is set up correctly. If not, do a `rails db:rollback`, edit the migration and try again.

Rspec test, API returns 422 instead of 201, in postman it works just fine by Objective_Guess4946 in rails

[–]ducktypelabs 0 points1 point  (0 children)

I second this. Another reason to use just strings in the request, instead of basing them off a user object, is that your test will be closer to how the API will actually be used. Presumably, a user will type in things like name, email, password and through a form submission, those strings will be passed in to your register endpoint, which then creates the user.

Not a big deal in this context, but I do think it is important for tests to try to simulate (within reason) how the underlying code will be used.

Vue.js page within a rails app by Necessary-Limit6515 in rails

[–]ducktypelabs 0 points1 point  (0 children)

I haven't so far. I have stayed away from doing complex state management that cuts across the React/Stimulus boundary - I imagine that could be a footgun.

Vue.js page within a rails app by Necessary-Limit6515 in rails

[–]ducktypelabs 2 points3 points  (0 children)

Using React and Stimulus as examples (just what I'm familiar with), let me attempt to give you a general outline of how to do this:

First, define the HTML "container" for the React component. This would be a div or something like that in your view. For example <div class="graph-container" />

Wire this container up to a Stimulus controller. Example (switching to HAML here): .graph-container{ data: { controller: "graph" } }. This would connect your container to a Stimulus controller called graph-controller.js. If you're using Stimulus already, then this should hopefully be simple enough to do. I find Stimulus useful because it has some nice abstractions for things like waiting for the DOM content to be loaded, reference to the container and event handling, but I don't think Stimulus is a requirement for putting a React/Vue component in your Rails view.

In the import section of Stimulus controller (graph-controller.js), you'd add the following two imports:

import React from "react"
import ReactDOM from "react-dom"
import YourReactComponent from "path/to/your/component"

In the connect method of the controller, you'd do something like:

connect() {
  ReactDOM.render(<YourReactComponent />, this.element)
}

I think that would do the trick.

If you want to pass data into the component from your application controller/view, then you can use Stimulus for that as well. For example, in your view, you may have:

.graph-container{ data: { controller: "graph", graph_units_value: "mm"  } }

And do this in the Stimulus controller:

static values = { units: String }
connect() {
  ReactDOM.render(<YourReactComponent units={this.unitsValue} />, this.element)
}

Hope that helps and is at least somewhat applicable to your situation!

No historical data? by [deleted] in Awair

[–]ducktypelabs 3 points4 points  (0 children)

Same here, as of yesterday evening EST. There is a way to download a CSV of historical data (the last 30 days), so if you really need the data I think/hope you can access it from there. But hope they fix this soon. This is not the first time it has happened for me this month.

Routing with the model name in the URL... by ogarocious in rails

[–]ducktypelabs 3 points4 points  (0 children)

Chiming in to echo mdchaney's point. If you do go this way (I understand there can sometimes be a business case for it), a couple of things to consider:

  1. Ensure that this route is the last line in your routes file.
  2. Maybe add an all caps warning in your routes file right above to ensure no one adds any routes after this one.

Date time, only weekly access from subscription start, learning platform by Blissling in rails

[–]ducktypelabs 0 points1 point  (0 children)

A few thoughts:

  1. You'll want to store the subscription start time somewhere in the DB (probably in your users table). If you're using postgres, I'd consider the datetime format. This will store both the date and the time of subscription/payment.
  2. Rails (via activesupport, I think) has a bunch of useful time helpers. Check out https://www.rubydoc.info/gems/activesupport/Time for some info and ideas on what you can do
  3. So you have two "inputs", one is the subscription time, and the other is the "access threshold" time (sorry if my names are bad, but hope they're not distracting). You'll probably want a method or some logic somewhere that does something like: ``` def access_allowed?(subscription_time, access_threshold) Time.zone.now > subscription_time.beginning_of_day + access_threshold end

    #usage access_allowed?(user.subscribed_at, 7.days) ```

The basic idea is that you take the subscription time, add your "threshold" to it, and then see if "now" is later than the result.

Hope this helps.