Dan Tappin

Joined

8,170 Experience
0 Lessons Completed
9 Questions Solved

Activity

Posted in Direct Uploads with ActiveStorage Discussion

On a side note any thoughts on adding an update to handle the deleting of uploaded files?

Posted in Direct Uploads with ActiveStorage Discussion

I followed this line for line - uploads work just fine except that when you update the record with new files the old ones are deleted. Is this the inteneded action or can you allow adding files to the collection?

I followed this and am getting the following errors:

definition.js:34 Uncaught TypeError: constructor.bless is not a function
    at blessControllerConstructor (definition.js:34)
    at blessDefinition (definition.js:28)
    at new Module (module.js:9)
    at Router.loadDefinition (router.js:63)
    at application.js:213
    at Array.forEach (<anonymous>)
    at Application.load (application.js:212)
    at Module../app/javascript/controllers/index.js (index.js:9)
    at __webpack_require__ (bootstrap:19)
    at Module../app/javascript/packs/application.js (application.js:1)

Anyone else see this?

Did you ever finish this? I am looking to do the exact same thing.

Posted in Going crazy with console / debugging issue

I have narrowed this down here is my example:

In a view if I throw in some garbage code like this in my model / view / controller:

<% qwerty %>

The page fails and I get the better_errors page.

I had a typo in a validation and then the console would hang and report the error:

Completed 500 Internal Server Error in 21ms (ActiveRecord: 4.0ms | Allocations: 19494)

NoMethodError - undefined method `map' for nil:NilClass:
  app/views/expenditures/_form.html.erb:6
  app/views/expenditures/_form.html.erb:1
  app/views/expenditures/edit.html.erb:9
  app/controllers/expenditures_controller.rb:39:in `update'

I was seeing this before but can't recall enough to recreate this. I have never seen this before.

Posted in Going crazy with console / debugging issue

In development mode I want errors to hit the browser and specificly the 'better_errors' gem debuging pages.

Currently when I hit an issue my console just hangs and reports the error and the browser just stalls. This is making it impossible to debug.

Thought it was pry but that wasn't it. Any ideas where to start looking?

That was awesome. I have some small logic to still sort out. Just a few points: you need to create a Components controller and inherit it from the Assets (unless you want your own). Same goes for Pundit policies but in my case I had to create a separate scope anyway. The controller logic is easy - you can call controller_name and set the Asset class for each type. The only thing that is a bit of a gotcha is the model associations. Now that it's a direct has_many and not polymorphic I found i need to set the type field in the create section of the controller. Also Asset.all will return both Assets and Components while Components.all only Components. Adding a default scope / Pundit policy_scope fixes that. All the routes now just handle them selves and in the views I have a now just a small bit of logic (that still needs for refactoring) to handle the asset / component conditions.

So let me get this straight then - I would add that inherited class, add the 'type' column and then add that as a normal nested resource under assets. If I post a new 'component' to the new_component path etc. the Asset controller still handles this but the 'type' would not get set. This is why I would need my own controller.

My first thought is keep the single controller and just add some logic to call 'Asset.create...' or 'Component.create...' etc. as required as it should be the same for both.

If you want some free rep over at SO cross post your answer there too :) http://stackoverflow.com/questions/37122490/can-i-alias-a-rails-active-model-to-another-class

Thanks for the tip Chris. I think that s what I am looking for. So from what I gather I add a 'type' column and Rails pretty much handles the rest. Do you make a separate controller too?

First off I am sure I am not asking this question correctly as this is an advanced Rails topic over my head right now. Here is what I have for routes:

concern :assetable do
resources :assets, concerns: [:workable, :trackable, :flagged, :historical, :commentable, :uploadable], shallow: true do
resources :assets, path: :components, as: :components, shallow: true#, only: [:index, :create, :new]
end
end  

and my asset model:

has_many :assets, :as => :assetable, :dependent => :destroy
alias_attribute :components, :assets

My premise here is I have an Asset model that can polymorphicly belong to pretty much any other model in my Rails app - including another Asset. My my case I am limiting this case to one level deep and calling these Components. This is like having a car as an asset and it has an engine, transmission etc. as a component. For my purposes it's simple enough to make a common set of attributes that are shared between both the assets and components,

Now I could just create an entire new model but the entire data structure, views controllers etc are for the most part the same so I figured that was just a waste of time and makes it a mess to keep this code in sync.

As I go along now I am having to add some logic to my views to ensure the headings i.e. "Assets" vs. "Components" and I have a simple instance variable in my controller @asset_class which returns 'asset' or 'component'. The ugly part now is when I start working with routes. All the awesome Rails url helpers etc. fail me here because if I call url_for( ) on a component record I get /assets/etc/etc when I really want /components/etc/etc/. I essentially want to Assets nested under Assets to be represented as Component class not Asset.

Can I do this?

Posted in Opinion: Destroy or not destroy

I think that's where I am headed. If I have lots of records / files that means I have lots of paying customers so it's all good.

I guess my question would be at what point would you want to purge a customers data? Let's say they quit and comeback a year later. There could be an advantage to have saved all that for them.

Posted in Opinion: Destroy or not destroy

I am working on an app and I have already added the paper trail gem (https://github.com/airblade/paper_trail) to track revisions. Now I am thinking that I want to add Paranoia (https://github.com/rubysherpas/paranoia) to soft delete. If I do that I figure I should keep all the uploaded documents associated with the various models. It's not that hard to implement and the down side perhaps is only storage space.

The big plus here is to provide an audit trail for models and an 'oops' option if someone deletes something by accident.

My initial thought is to just implement it without making the ability to rollback etc public but then just have the option to do it later.

1.) Does this seem like a good idea?

2,) Does anyone have experience with this either way?

Anyone seeing this not work in Safari? It works in Crome.

Posted in Multitenancy with the Apartment gem Discussion

Anyone got this working with Active Admin?

Posted in Reoccurring events with simple_calendar and ice_cube

I have been chewing on this for a few days. I am thinking about it too much. If I read that link correctly they do it like I was planning. The event belongs to "recurringEventId". I am going to ignore the idea of removing single events, re-scheduling for now. I am going to get it up and running with a minimal feature set and then add those later (if I even need to).

I think I will have Events in one of 5 states:

  • complete
  • active (this is the next event in the queue)
  • cancelled (for some reason you decided to not complete that occurrence)
  • deferred (you still plan to complete it but the system will not remind you until the deferred date)
  • planned (all events after the active one - just placeholder to fill the calendar

The Tasks then have perhaps have 3 states:

  • open (the Events show in the calendar, reminders are sent etc.)
  • paused (not sure on the Event logic here yet)
  • closed (future Events are cleared etc.)

Posted in Using Pundit with ActiveAdmin

New issue posted here:

https://github.com/activeadmin/activeadmin/issues/4264

Have a look at my dummy app:

https://github.com/jasper502/aa_with_pundit_user

Unless I am missing something obvious it's clearly broken.

Posted in Using Pundit with ActiveAdmin

Thanks - I will give that a shot.

Posted in Using Pundit with ActiveAdmin

See my SO post for an update. I found a solution but I would still like to know if this is an isolated issue with my code or an issue with AA / Pundit.

From what I can tell AA is not calling authorize or policy_scope at all. Once you force it to it works (for the most part).

Posted in Using Pundit with ActiveAdmin

I don't know where to start and can't even confirm that it not an issue on my end.

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.