I was looking at helpy.io which looks like it uses Devise. Any tips / pointers on syncing the two databases?
Does anyone have a suggestion to integrate your main Devise based Rails app with a secondary related site?
In my example I have a standard Rails app behind authentication with Devise. I want to also have a separate support / knowledge base site behind the same authentication (i.e. single sign on). It would look like this:
- app.mysite.com (main site - user login)
- help.mysite.com (sub site - user has access when currently logged into the main site)
I was thinking that it would be some sort of OMNIAuth or LDAP but could it be as simple as an encrypted token in a cookie? If you don't have that cookie set you just get a redirect to the main site login page? Thoughts?
Two reasons - if you have a wreck you cant easily find ophaned files.
I also have clients than need data segrigation.
I am going with an 'Attachment' model which belongs to other models (just one for now).
The 'Attachment' model to add other fields and funtionality down the road. Each record has one file uploaded against it.
I started with ActiveStorage but am abandoning that because AS just dumps all your files into the root of your filestore. So down the road when I have a million uploads I have a mess. Carrierwave (and other gems) let you organize your uploads into organized directories etc.
I am currently just using a nested form and ActiveStorage in my edit view. It works but is clunky. I wanted to use Dropzone (as I used a few years back) but it doesn't seem to support nested attributes.
Is there a modern and easy to use combination of gems / JS to do this based on my set-up?
Posted in DataTables Install via Webpacker
Anyone get this to work?
I created a secondary model
Attachments to add has_attached to so I could add additional fields. The issue is that there no easy way to validate the presence of an attachment. Also when my validation on the other fields fails the previously uploaded file does not seem to persist to the render :edit page.
It's a bug in Rails 6rc: https://github.com/rails/rails/issues/36374
On a side note any thoughts on adding an update to handle the deleting of uploaded files?
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:
Anyone else see this?
Did you ever finish this? I am looking to do the exact same thing.
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.
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?