Dan Tappin

Joined

8,170 Experience
0 Lessons Completed
9 Questions Solved

Activity

Posted in Using Pundit with ActiveAdmin

On a side note Chris I suspect you have a view bug on the questions home page. Look at this thread. I made the last post but alexander's avatar is shown. Is this the intent? It threw me for a second as I saw my name and someone else face. If the idea is that it's his topic that makes sense but it's a bit confusing in that context.

Posted in Using Pundit with ActiveAdmin

I am not sure if that's the issue. Here is a comprehensive post I just created on this issue:

http://stackoverflow.com/questions/34664645/active-admin-devise-and-pundit-punditpolicyscopingnotperformederror

I think it's a bigger (or simple) issue. My AA policies seem to not being referenced at all. If I say try and load /admin/users Pundit is using the /policies/user_policy.rb file and not /policies/active_admin/user_policy.rb.

In my case (for now) my AA policies are all true until I decide to lock down AA access when I open it up to other users. In the near term it's just me in there so I am the only one to blame if data gets deleted by accident :)

Posted in Using Pundit with ActiveAdmin

Did you ever get this working? I am stuck at the same issue. Can you just disable Pundit for AA entirely?

Posted in Reoccurring events with simple_calendar and ice_cube

I am developing a Rails app that has a Task model. It's like any basic task tracking system where you can set some attributes (name, activity, status, priority etc.) and a due date. For my system I am sticking with just dates but I am actually going to use datetime types to plan for the future if I change my mind.

Simple one-off tasks are easy but most you would want to re-occur. After a lot or Googling in my opinion the best Rails solution is ice_cube (https://github.com/seejohnrun/ice_cube) with recurring_select (https://github.com/GetJobber/recurring_select). recurring_select makes it dead simple to schedule complex repeating events and then use ice_cube to do all the heave lifting for the scheduling.

There are lots of calendars out there but as the name suggests simple_calendar seems to be an obvious choice. With most re-occuring calendars the issue is parsing the events in a time period. There is no really easy way to say find all your Tasks that fall in a window of time (for example a simple_calendar given month). You would end up needing to loop through ALL of your events for a given day and parse out the ones that fall on that day.

Here is my idea - with a given Task when you create up update the task there is a call back that creates / updates an Event that for the most part is a simple model with a Task foreign key and a date. These belong_to Task. There is one drawback I see. You would need to set a limit (say 10 years) to auto-generate Events. It would seem trivial to also be able to set an update_date column based on the schedule that you could use on a nightly rake / sidekiq task to run though an regenerate more future events.

Now you can pass the Events.all or any other ransack search etc. into simple_calendar for display. You can then just call event.task.attribute to get the parent data.

For my system I want to have comments, attachments etc. for completed tasks. When an Event is completed the parent Task is cloned with the original being saved as the read-only record for the last Event and the new cloned Task would be set back to 'active' or some other status and the new Events generated from it. All these Tasks would have some sort of common UUID like the ancestry gem or something like that. You can then see the previous tasks history etc. For example in my case I would be tracking a cost component. You could then see a long term trend in the costs etc.

I want to keep this simple but I see some issues that could make this (and any other system) get ugly fast.

  • re-scheduling future events
  • removing single events
  • changing the parent ice_cube rule and how to handle the two items above

Thoughts / comments / suggestions?

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Issue also on Stackexchange:

http://stackoverflow.com/qu...

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Now its:

rake stdout: Nothing written
rake stderr: rake aborted!
NoMethodError: undefined method `tr' for nil:NilClass
/home/deploy/test_deploy/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:37:in `initialize'

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

I realized that I had not updated my remote database.yml file

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

The Java runtime needs to be noted also. I am stuck here in the deploy stage:

Psych::BadAlias: Cannot load `Rails.application.database_configuration`:
Unknown alias: default

Google results in lots of comments about your default section of your database file. I took those right out and hard coded them vs the alias and I still get this error.

Exactly - the more I think about it postgeSQL schemas or the apartment gem are a great way to segregate data but create a lot of work.

Here is a related StackExchange post of mine to consider:

http://stackoverflow.com/questions/28513849/rolify-and-acts-as-tenant-with-single-signon-with-some-devise-pundit-on-the-s

Any thoughts on acts_as_tenant vs. apartment?

The multiple database per tenant seems bulletproof but would get ugly with lots of tenants. The odds of something going wrong with migrations etc. does not seem worth the risk.

acts_as_tenant seems to implement the system I was going to anyway.

I think I figured it out. I stumbled across this:

https://gist.github.com/6dd44fc841e80bbc2265.git

I switched my routes to "user/..." from "devise/..." and that seemed to do the trick.

Hmmm... took my routes and tried this for fun:

devise_for :users, :skip => [:sessions], :controllers => { :registrations => 'users/registrations', :sessions => 'users/sessions' }
as :user do
get '/signin' => 'devise/sessions#new', :as => :new_user_session
post '/signin' => 'devise/sessions#create', :as => :user_session
delete '/signout' => 'devise/sessions#destroy', :as => :destroy_user_session
end

I wanted to see if the normal Devise routes work and they do except that now the validation fails completely. If I submit a blank form I get all kinds of errors but if I fill it out it works fine now. I am getting close but obviously missing something small here.

I have posted a few related questions on this but now I am at a road block. I had this system working quite well and then I went to add to it and now I broke it real good!

First off I just discovered Gist so here is my code:

https://gist.github.com/jasper502/065a63fde266fac1fbf5

The idea here is that I have a single User login that can eventually be tied to multiple Companies via the Role.

You signup via Devise on the custom /register route and fill out the Company information etc. The custom registration controller creates the Role during the user creation and sets a few other attributes.

When I try to create a new user / company the additional user fields (name_first & name_last) always fail validation regardless if they are in fact valid. The nested Company fields do not validate at all. If I enter the email and password field only the form works but only creates the User record.

To me it seems like the custom registration controller is not being processed at all because it seems to not want to allow my additional params specified in sign_up_params

Posted in Updating Nested Form / Model Attributes

I have a nested form on a Devise signup page. The user signs up and then they also fill out their company info (Name , Address etc.). My User and Company model are associated through a Role model which has id_user and id_company. My form has nested form_for tags for the Role and Company models. The sign-up works like magic and the Role is created automatically with the id_user and id _company filled in.

Now the part I can't figure out. When they sign up the Company is new and the User is the first and therefore should be the 'owner' Role. I have some other attributes I want to set ( :role => 'owner', :active => 1, :default_role => 1 etc.). The role attribute will be used later for an authorization system - probably with Pundit.

I want to do this on the backend with the controller. The intermediate Role is created via 'magic' but can you hook into that process and further update the record? I know I could probably add a hidden field in the form but to me that is opening a security hole. Here is my StackExchange post that has the code etc.:

http://stackoverflow.com/questions/28039893/how-do-i-update-a-nested-resource-without-passing-the-data-via-a-form

Posted in Multi Model Sign-up Wizard

Posted in Multi Model Sign-up Wizard

I forgot to mention - I tried your method and the user gets created but the company is not getting created and there is no errors or even any active record activity in the logs when it happens. I suspect I have my associations messed up because there is no direct link between User and Comapny with Role in the middle.

Posted in Multi Model Sign-up Wizard

Yes - that's essentially what I am doing.

My system has some differences. First off the user could exist already. As long as the company is unique they can continue.

Second I have a Role model that associates the User to the company. I need to create / identify the user, create the company and a role all at the same time and like I mentioned roll it all back if any validation fails.

This is where I struggled with even letting people sign up directly. At first I thought I would set up a company manually and add the first owner user. This way I can watch for duplicate companies etc outside of a normal validation etc.

However with a direct sign up people can get into a trial account an start test driving the site right away.

Posted in Multi Model Sign-up Wizard

I was tying to implement this and had a revelation - I need to register the Company and then using nested forms to create the user and role. Once the user registers the company the user is automatically created (unless they exist) and then the role is created to glue the two together.

Now - I have already created my default Devise install on the User model. I still want to use Devise for authentication but can I still use it for registration or I am overriding manually? Once a company is created all new users created under that company will be by another existing user. You will not be able to signup unless you are creating a new company.

I think in this case I can handle the validations in my controllers. It's a bit ugly with all the :through associations.

Posted in Multi Model Sign-up Wizard

I am going to go with the email only. It's just easy - I personally hate having to pick a username. My email is the easiest thing to remember.

Here is a great link I came across on the very subject:

http://blog.codinghorror.com/the-god-login/

It even gets into login vs signing and signup vs register.

Thanks for the tip on the nested model validation :)

Posted in Styling with Bootstrap Sass Discussion

I started a new app today and it seems that the docs have changed:

https://github.com/twbs/boo...

You need to remove the require directives from your css files but when you do that it seems that all the other CSS files do not get included. You need to manually import each one in your new application.scss file. I seem to be missing something here (and I did save my files this time ;^)

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.