hnanon

Activity Graph

Page 1 of 19 | Next »

2018-11-14

[00:47:59] hnanon: has joined #RubyOnRails
[00:50:14] hnanon: I have a CollectionProduct join model between Collection and Product models.
[00:50:57] hnanon: Within an admin namespace (/admin/products/1/) I have the line: <%= link_to 'Remove', @product.collections.destroy(collection), method: :delete, data: { confirm: 'Are you sure?' } %>
[00:51:33] hnanon: When I go to that page, the actual collection is destroyed (without clicking the link!).
[00:51:56] hnanon: How can I just destroy the record within the joins table?
[00:52:54] hnanon: In other words, just visiting the page calls the destroy method.
[00:55:25] hnanon: Which controller should the destroy action be in?
[00:55:31] hnanon: Products?
[00:56:04] hnanon: Yes, exactly.
[00:58:50] hnanon: What about using creating and using a collection_products controller?
[00:59:07] hnanon: *creating and using
[01:04:43] hnanon: Can I pass two arguments to its named path...something like: admin_collection_products_path(@product, collection)?
[01:09:42] hnanon: It looks like I can pass params to the path.
[01:10:57] hnanon: So, something like admin_collection_product_path(product: @product, collection: collection).
[01:11:17] hnanon: Then I can access those params like normal in the destroy action.
[01:11:42] hnanon: Or, is that convoluted and I'm overthinking it?
[02:38:13] hnanon: Remote host closed the connection
[02:38:42] hnanon: has joined #RubyOnRails
[04:23:12] hnanon: Remote host closed the connection
[04:23:39] hnanon: has joined #RubyOnRails
[04:24:42] hnanon: Remote host closed the connection
[04:25:10] hnanon: has joined #RubyOnRails
[04:27:12] hnanon: Remote host closed the connection
[04:27:40] hnanon: has joined #RubyOnRails
[07:02:28] hnanon: Ping timeout: 264 seconds

2018-11-13

[01:27:30] hnanon: Hey Radar.
[01:29:23] hnanon: Am I remembering that correctly?
[01:29:23] hnanon: I remember, years ago, you said something about shopping carts and orders being basically the same, just in different states...or something like that.
[01:42:56] hnanon: Yeah, really.
[01:43:34] hnanon: Your opinion is different now?
[01:44:59] hnanon: I see. Cool. I'm working on an ecommerce app at the moment.
[02:03:46] hnanon: Ping timeout: 244 seconds
[05:00:15] hnanon: has joined #RubyOnRails
[05:04:42] hnanon: Ping timeout: 252 seconds
[14:19:33] hnanon: has joined #RubyOnRails
[15:07:06] hnanon: Ping timeout: 260 seconds
[15:13:19] hnanon: has joined #RubyOnRails
[15:25:35] hnanon: Quit: Leaving
[23:23:39] hnanon: has joined #RubyOnRails
[23:41:09] hnanon: Ping timeout: 250 seconds

2018-11-12

[17:18:59] hnanon: has joined #RubyOnRails
[17:24:49] hnanon: I have this line in a VariantOption model: attribute :option_name
[17:25:01] hnanon: It's using the new 5.2 attributes api.
[17:25:44] hnanon: In my Variants controller I have @options.each { |name, id| @variant.variant_options.build(option_name: name, option_id: id) }
[17:26:10] hnanon: So, with that, I'm assuming I should be able to access the option name with :option_name.
[17:26:37] hnanon: However, when I do:
[17:26:55] hnanon: <%= variant_option.text_field :value, placeholder: :option_name %>
[17:27:17] hnanon: The placeholder text is only "Option name," without the the actual name of the option.
[17:27:21] hnanon: Any ideas?
[17:28:57] hnanon: :option_id does indeed show the actual option id.
[17:29:31] hnanon: Why does :option_name not show the option name?
[17:31:09] hnanon: Doing @options.each { |name, id| puts name+id.to_s } does print both the name and id so I know that name is present.
[17:58:28] hnanon: Finally, after all last night and this morning...I had to do: placeholder: variant_option.object.option_name
[17:58:38] hnanon: That "object" was key.
[17:58:54] hnanon: Is that documented anywhere (the use of "object").
[18:30:26] hnanon: Ping timeout: 260 seconds
[19:52:08] hnanon: has joined #RubyOnRails
[21:27:34] hnanon: Ping timeout: 246 seconds
[23:41:36] hnanon: has joined #RubyOnRails

2018-11-10

[02:07:08] hnanon: has joined #RubyOnRails
[03:32:36] hnanon: Ping timeout: 252 seconds
[03:45:41] hnanon: has joined #RubyOnRails
[05:24:15] hnanon: Ping timeout: 252 seconds

2018-11-09

[00:52:39] hnanon: Read error: Connection reset by peer
[16:45:36] hnanon: has joined #RubyOnRails
[16:46:13] hnanon: Should timestamps be stored as integers or datetime?
[16:46:44] hnanon: Is there a preference or convention (besides the created_at and updated_at attributes)
[16:53:08] hnanon: crankharder, They're datetimes for created_at and updated_at.
[16:53:42] hnanon: I'm using Stripe and one of their data fields is a timestamp as an integerr.
[16:54:02] hnanon: I wasn't sure if I should convert it or just keep in their native version.
[17:35:48] hnanon: Ping timeout: 272 seconds
[19:39:10] hnanon: has joined #RubyOnRails
[20:07:41] hnanon: Read error: Connection reset by peer
[20:08:10] hnanon: has joined #RubyOnRails
[22:29:36] hnanon: Read error: Connection reset by peer

2018-11-08

[22:46:23] hnanon: has joined #RubyOnRails
[22:47:24] hnanon: Is it normal for nested fields to be duplicated on a create (validation) error?
[22:48:33] hnanon: New action has @subscription.notifications.build
[22:50:12] hnanon: Nevermind. It's always a silly mistake.
[22:50:27] hnanon: I was calling fields_for twice in the form.

2018-08-08

[19:46:54] hnanon: has joined #RubyOnRails
[19:48:51] hnanon: I have a User model with a profile image attachment, attached via Paperclip. I newly create a Profile model and it now will have that image as an attribute (instead of the User having it). I also migrated to ActiveStorage.
[19:48:58] hnanon: New attachments work fine.
[19:49:19] hnanon: How can I migrate the older referenced images from the User table to the Profile table?
[19:49:52] hnanon: I'm trying to follow this guide: https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md
[19:50:16] hnanon: However, that just migrates from the User table to the same User table.
[19:50:36] hnanon: I'm not sure how to adopt it to migrate to the Profile model.
[20:10:10] hnanon: Inside: from PC to AS.
[21:40:30] hnanon: Ping timeout: 252 seconds

2018-07-17

[21:48:29] hnanon: has joined #RubyOnRails
[21:50:50] hnanon: If I have a has_one relationship...let's say Book has_one Author...after the Author is created and associated with a Book, what happens when I recreate an Author for the same Book? Does it just update the existing Author? If not, shouldn't it?
[21:51:55] hnanon: Or, does a new Author get created with same Book association as the existing, first Author?
[21:52:45] hnanon: If the latter is the case, how does rails know which author to use for the Book's has_one relationship?
[21:53:15] hnanon: I'm asking because, for ActiveStorage, the attachment is updated in that case, and not created.
[21:53:24] hnanon: *not recreated
[21:57:35] hnanon: So, a new object is in fact recreated when there is an existing has_one association.
[21:58:30] hnanon: Additionally, rails uses the first object. So, Book.last.author returns the first author, for example.
[21:58:37] hnanon: Is that how it should be?
[22:51:27] hnanon: Ping timeout: 252 seconds

2018-06-20

[18:57:06] hnanon: has joined #RubyOnRails
[18:58:06] hnanon: I'm trying to use the Adwords API.
[18:58:33] hnanon: There is a adwords_config.yml file in my rails config directory.
[18:58:56] hnanon: There is also a setup_oauth2.rb in the config directory.
[18:59:09] hnanon: That setup file has a line: adwords = AdwordsApi::Api.new
[18:59:24] hnanon: The comment for that line is:
[18:59:44] hnanon: AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml when called without parameters.
[19:00:15] hnanon: How can I instruct it to read the adwords_api.yml file from my config directory instead of the home directory?
[19:02:21] hnanon: This is at the top of the config file: require 'adwords_api'
[19:02:41] hnanon: Is that where I should define its location?
[19:11:39] hnanon: nzst: Ha. Thank you.
[19:37:41] hnanon: Quit: Page closed

2018-05-15

[00:20:30] hnanon: Ping timeout: 260 seconds

2018-05-14

[21:42:38] hnanon: has joined #RubyOnRails
[21:43:25] hnanon: I have the following line:
[21:43:37] hnanon: <%= grouped_collection_select(:user, :location_id, @markets, :locations, :name, :id, :name, { prompt: "Select Primary Location", selected: @user.location_id }, { class: "form-control" })%>
[21:43:57] hnanon: So, the collection is markets, but I'm grouping by locations.
[21:44:55] hnanon: How can I only get locations with a particular attribute ie. where(status: "active")?

2018-03-19

[16:20:03] hnanon: has joined #RubyOnRails
[16:28:52] hnanon: I need some help crafting an ActiveRecord query.
[16:29:01] hnanon: This is what I have so far: https://gist.github.com/anonymous/7b1ca164dd0dc284d634668e048fa748
[16:29:20] hnanon: That's the goal, I should say.
[16:29:54] hnanon: Of course, I can get each piece individually. But, I don't know how to group them.
[16:43:15] hnanon: I should also say that the tables are not related.
[17:04:10] hnanon: Ping timeout: 260 seconds

2018-01-05

[05:55:27] hnanon: has joined #RubyOnRails
[07:17:10] hnanon: Ping timeout: 260 seconds

2018-01-02

[00:09:24] hnanon: Ping timeout: 260 seconds

2018-01-01

[23:36:45] hnanon: has joined #RubyOnRails
[23:39:05] hnanon: I have a Card model that belongs to Account.
[23:39:32] hnanon: I create the Card when creating a Subscription.
[23:39:48] hnanon: I want to merge the account in the params.
[23:39:53] hnanon: I'm doing something like:
[23:40:04] hnanon: params.require(:subscription).permit(:category_id, :market_id, cards_attributes: [:name]).deep_merge(cards_attributes: [account_id: @account.id])
[23:40:35] hnanon: This gives me the error: undefined method `deep_merge' for #<ActionController::Parameters:0x007f37e6cd8190>
[23:41:01] hnanon: When I just use "merge", the account is merged in the params but the name is not.
[23:41:18] hnanon: It's as if the cards_attributes is being overwritten.
[23:42:07] hnanon: How can I merge the account in the cards_attributes params while maintaining the existing params?
[23:43:26] hnanon: params look like this:
[23:43:37] hnanon: subscription"=>{"market_id"=>"5", "cards_attributes"=>{"0"=>{"name"=>"Name Here"}}
[23:44:07] hnanon: Radar: Yes, I was going to do that. But I wasn't sure if merging in the params would be better.
[23:46:20] hnanon: Radar: In a before save?
[23:51:01] hnanon: Radar: Ok. I Just did @subscription.cards.first.account = @account
[23:51:09] hnanon: ...and it's working fine now.
[23:51:17] hnanon: Thank you.
[23:53:22] hnanon: I placed that line above before saving the subscription. There was no need to explictly save the card.
[23:55:25] hnanon: Thanks, as always.

2017-12-30

[03:57:49] hnanon: has joined #RubyOnRails
[03:58:15] hnanon: How do I add a namespace to a form in 5.2?
[03:58:36] hnanon: The edge guides don't appear to be updated.
[03:59:05] hnanon: ...using form_with.
[04:03:25] hnanon: Found it in the api:
[04:03:32] hnanon: <%= form_with(model: [:admin, category], local: true) do |form| %>
[04:03:48] hnanon: Quit: Page closed

2017-12-29

[21:39:51] hnanon: has joined #RubyOnRails
[22:01:00] hnanon: Is there a copy of the default gem file for Rails edge somewhere?
[22:22:17] hnanon: Penguinlay:No. I mean the gem file for the latest Rails version.
[23:18:30] hnanon: Ping timeout: 260 seconds

2017-11-22

[00:03:12] hnanon: Radar: @categories = Category.all
[00:03:26] hnanon: Similarly for @markets
[00:04:59] hnanon: <%= category.revenues.sum(:amount) %> gives me the total revenue across all markets...
[00:05:43] hnanon: To get the revenue for each market...
[00:14:06] hnanon: Radar: Almost there...
[00:14:09] hnanon: Radar: <%= category.revenues.joins(:location).where(locations: { market_id: 2 }).sum(:amount) %>
[00:14:21] hnanon: I'm hardcoding the market_id for now...
[00:14:32] hnanon: It's correctly showing the sum for each id.
[00:21:18] hnanon: Radar: https://gist.github.com/anonymous/138c877b5db49cfec679997b35e79e83 !
[00:47:05] hnanon: Radar: Thank you for your help.
[00:47:34] hnanon: Radar: You always come through and I really appreciate it.
[00:47:47] hnanon: creature: Thank you too.
[01:03:55] hnanon: Ping timeout: 260 seconds

2017-11-21

[23:03:56] hnanon: has joined #RubyOnRails
[23:21:14] hnanon: I'm having a hard time writing a query and displaying the results in a view.
[23:21:24] hnanon: This is what I have so far: https://gist.github.com/anonymous/5ae8495e38c03ebdfa141572dd21e816
[23:21:37] hnanon: The sample html file is basically a ledger.
[23:22:15] hnanon: It lists markets and revenues across categories, with totals.
[23:25:54] hnanon: creature: I'm able to get market name listed.
[23:26:18] hnanon: creature: I'm just not sure how to construct the join and group.
[23:27:01] hnanon: @revenues = Revenue.joins(:location).group("locations.market_id", "category_id")
[23:27:21] hnanon: That gives me an array of revenues grouped by category_id.
[23:27:35] hnanon: I think I need the array grouped by market first.
[23:35:22] hnanon: creature: 1 min, please
[23:39:59] hnanon: creature: What kind of raw data?
[23:40:12] hnanon: I have existing db records
[23:40:23] hnanon: For example, from the Revenues table
[23:41:35] hnanon: creature: Can you take a look at the sample html file in my gist above?
[23:41:51] hnanon: creature: I think I'm approaching this all wrong.
[23:44:01] hnanon: creature: No, it's not :)
[23:44:20] hnanon: I just have some tables of data...
[23:44:44] hnanon: This is a sample output: https://gist.github.com/anonymous/96fc2f2d8fcbacd07404e6945bbcc8a6
[23:46:02] hnanon: Let me back up...
[23:46:30] hnanon: I have Revenue. Each revenue record has a location and category.
[23:46:40] hnanon: Each location belongs to a Market.
[23:47:03] hnanon: I want to sum the revenue for each market for each category.
[23:49:49] hnanon: Radar: But table columns are grouped by Market. Does that make a difference where I start from?
[23:50:12] hnanon: creature: Yeah, it's wrong. The markets behind those location ids are different.
[23:55:11] hnanon: Radar: 1 sec.
[23:58:51] hnanon: Radar: That's done.
[23:59:55] hnanon: Next assignment/clue...

2017-09-14

[00:08:42] hnanon: has joined #RubyOnRails
[00:08:49] hnanon: Hi everyone.
[00:10:05] hnanon: I want to obfuscate the ids in my routes. I have a slug attribute and I want to use it along with a timestamp value (in milliseconds) as the param instead of the id.
[00:10:23] hnanon: Is that an acceptable approach?
[00:10:58] hnanon: The timestamp would be the slug value.
[00:13:36] hnanon: Is it reasonable to expect that there wont be a collision if I'm using Unix time in milliseconds as the unique identifier?
[00:29:40] hnanon: tcopeland: I thought about uuids but I think they're too long for my needs.
[00:32:55] hnanon: tcopeland: That article is helpful, though. Thank you.
[00:54:58] hnanon: Quit: Page closed

2017-08-28

[00:10:19] hnanon: Ping timeout: 260 seconds

2017-08-27

[14:24:42] hnanon: has joined #ruby
[14:29:19] hnanon: Ping timeout: 260 seconds
[23:35:09] hnanon: has joined #RubyOnRails
[23:36:52] hnanon: I have this model: https://gist.github.com/anonymous/b9cdbd21c1d4798db66a97035e97cb0b
[23:37:06] hnanon: I'm getting the error: undefined local variable or method `scores' for #<Class:0x007f0404d7bbd0>
[23:37:23] hnanon: I'm trying to access values in a hash from another method.
[23:37:31] hnanon: The hash is named "scores."
[23:38:31] hnanon: What is the correct way to do it? Include the hash within the method?
[23:39:05] hnanon: Or make the hash a global variable?
[23:40:25] hnanon: something like: https://gist.github.com/anonymous/263e54fcbd10182ec50c9db4348b353e
[23:45:13] hnanon: It won't change.
[23:45:46] hnanon: However, I don't see any scores printed. This is my relevant controller action: https://gist.github.com/anonymous/f6e8442561a32dcaa9b9359a9f2f6559
[23:46:03] hnanon: Radar: Good morning.
[23:47:07] hnanon: A string.
[23:47:37] hnanon: Something like "acca"
[23:48:08] hnanon: It's entered by the user. I upcase them all later.
[23:49:35] hnanon: 1. fixing now...changing to strings.
[23:49:47] hnanon: My string is upcased before it hits the model.
[23:51:23] hnanon: matthewd: Explain please.
[23:51:37] hnanon: I see the scores now, by the way.
[23:53:21] hnanon: matthewd: Understood. Fixed. Thank you.
[23:54:15] hnanon: Radar: Thanks too.

2017-08-26

[00:26:42] hnanon: has joined #RubyOnRails
[02:53:44] hnanon: Ping timeout: 260 seconds