Matt Bjornson

Joined

18,410 Experience
171 Lessons Completed
2 Questions Solved

Activity

Are you using GA for the public parts of GoRails or are you also using it for the authenticated parts of GoRails too?

Thanks Nathan,
I was thinking something like that as well, but I'm pretty new to how ActionCable works so am stumbling through this a bit... Good to know that I had thought through this in a decent way despite not knowing how to implement this. Do you think that it'd be good to add something to connection.rb to deal with multitenancy and whethere 'current_account' is set?

How would you limit those users by tenant ( account)? Would you make the data sent to redis an array of two integers, like [1, 2] where 1 is the account.id and 2 is the user.id? Or is there a simpler way to approach this?

Dale,
What did you settle on? I'm planning on taking the approach to start with sprinkling Vue components within rails and let this evolve naturally. I personally do not have the skills to do a full blow SPA with Vue so this was an easy decision for me. What I'm struggling with is how to best sprinkle those components throughout my rails app. The GoRails videos have been super helpful, and I'm using the approaches that Chris has highlighted

  • using the content_tag
  • using the App mounted to a div

I'm still experimenting on using vuex and using vue components within forms.

Posted in How do I use easyautocomplete in rails 6?

@Umar did you add jquery to your environment.js file? Something like,

const webpack = require('webpack')
environment.plugins.prepend('Provide',
    new webpack.ProvidePlugin({
        $: 'jquery/src/jquery',
        jQuery: 'jquery/src/jquery',
        'window.jQuery': 'jquery'
    })
)

Posted in Rails & Vue.js Trello Clone - Part 3 Discussion

If I don't want to drag and drop the columns, will I just remove the draggable directive from the columns? I still want to be able to drag cards from column to column ( and update the database) as well as modify the position of cards within the lists.

Thoughts?

I'm not sure what happened, but I had a production environment/config working with nginx/passenger deployed on Digital Ocean. I am not seeing errors in log files, but nginx is throwing a 500 when I try to access the rails app.

sudo passenger-status

Version : 6.0.4
Date    : 2020-02-15 04:02:15 +0000
Instance: xfvpDfe9 (nginx/1.14.0 Phusion_Passenger/6.0.4)

----------- General information -----------
Max pool size : 6
App groups    : 1
Processes     : 2
Requests in top-level queue : 0

----------- Application groups -----------
/home/deploy/crispy-sniffle/current (production):
  App root: /home/deploy/crispy-sniffle/current
  Requests in queue: 0
  * PID: 5005    Sessions: 0       Processed: 2       Uptime: 16s
    CPU: 2%      Memory  : 61M     Last used: 4s ago
  * PID: 5028    Sessions: 0       Processed: 1       Uptime: 15s
    CPU: 2%      Memory  : 46M     Last used: 15s ago
        ```

        /etc/nginx/sites-enabled/crispy-sniffle
        ```
        server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        passenger_enabled on;
        #passenger_ruby /home/deploy/.rbenv/versions/2.7.0/bin/ruby;
        passenger_app_env production;
        root /home/deploy/crispy-sniffle/current/public;


        location /cable {
            passenger_app_group_name myapp_websocket;
            passenger_force_max_concurrent_requests_per_process 0;
        }
        # Add index.php to the list if you are using PHP
        #index index.html;

        server_name shapeandship.com www.shapeandship.com;
        # Allow uploads up to 100MB in size
        client_max_body_size 100m;

        location ~ ^/(assets|packs) {
            expires max;
            gzip_static on;
        }
                }
                ```
                /var/log/nginx/error.log
                ```
                [ N 2020-02-15 04:01:31.6096 4918/T1 age/Wat/WatchdogMain.cpp:1373 ]: Starting Passenger watchdog...
[ N 2020-02-15 04:01:31.6503 4930/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2020-02-15 04:01:31.6505 4930/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2020-02-15 04:01:31.6589 4930/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 4930
[ N 2020-02-15 04:01:34.0365 4930/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)

I can see my browser hitting nginx in /var/log/nginx/access.log

196.52.2.101 - - [15/Feb/2020:03:45:46 +0000] "GET / HTTP/1.1" 500 2363 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13$
196.52.2.101 - - [15/Feb/2020:03:51:15 +0000] "GET / HTTP/1.1" 500 2363 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13$
196.52.2.101 - - [15/Feb/2020:03:53:23 +0000] "GET / HTTP/1.1" 500 2363 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13$
196.52.2.101 - - [15/Feb/2020:04:01:59 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.$
196.52.2.101 - - [15/Feb/2020:04:02:00 +0000] "GET / HTTP/1.1" 500 2363 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13$
196.52.2.101 - - [15/Feb/2020:04:02:12 +0000] "GET / HTTP/1.1" 500 2363 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13$

lastly /etc/nginx/conf.d/mod-http-passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_root /home/deploy/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/passenger-6.0.4;
passenger_ruby /home/deploy/.rbenv/versions/2.7.0/bin/ruby;

What am I doing wrong? Any help would greatly be appreciated.

Posted in Inviting Users with devise_invitable Discussion

Hey Chris, I'm trying to figure out your solution above, User.invite!({email:
new_user@example.com'}, current_admin)
with the solution you presented in this video where you added a set_user_id method to ProjectUser.rb

Since current_admin is a controller helper, how would you pass that to the ProjectUser model? Thanks!

Posted in Migrating From jQuery to Vanilla Javascript Discussion

I'm a bit of a javascript n00b but I found a solution... My updated fetchUsers method...

fetchUsers(text, callback, account) {
    let accountId = document.querySelector("trix-editor").dataset.mentionsAccount
    console.log(`This is from fetchUsers ${accountId}`)
    fetch(`/accounts/${accountId}/mentions.json?query=${text}`)
    .then(response => response.json())
    .then(users => callback(users))
    .catch(error => callback([]))
  }

Posted in Migrating From jQuery to Vanilla Javascript Discussion

I'm building an app that will have this feature, but I also am dealing with multi-tenancy. So how do I pass the account_id ( from multitenancy) in the fetchUsers call, here's what I have and it's not working ( I'm getting an undefined error).
mentions_controller.js

initialize() {
    this.account = this.data.get("account")
  }

fetchUsers(text, callback, account) {
    let account = this.account
    fetch(`/accounts/${account}/mentions.json?query=${text}`)
    .then(response => response.json())
    .then(users => callback(users))
    .catch(error => callback([]))
  }

and in _form.html.erb

<%= f.rich_text_area :problem, placeholder: 'The raw idea, use case, something that motivates us to work on this.', data: { controller: "mentions", target: "mentions.field", mentions_account: current_account.id} %>

I know the account_id is getting to the initialize method, but not the fetchUsers method. Any thoughts?

I finally figured out what the issues were ( there were multiple)...

  1. for the routing issue above in my last post, it was related to adding current_user.id on to the edit_user_registration_path route. The issue is that devise isn't expecting a user.id for that route.
  2. Also related to the edit_user_registration path requiring :password, it wasn't because I misconfigured the devise_parameters_sanitizer, it was because ( for whatever reason), I added to my user.rb validates_length_of :password, allow_blank: false once I removed that line, everything worked fine.

I'd also add that something doesn't seem quite right as my url for this edit route looks like this....

http://localhost:3000/users/edit.584a1cc3-844d-4b47-9281-dfc520a749b1

note: I'm using UUIDs instead of regular IDs.

I've followed the instructions on the devise wiki. I'd like a user to be able to modify their name, username, and email via the new_user_registration route. I keep running into the error where devise is expecting a password with greater than 1 character.

In RegistrationsController,

class RegistrationsController < Devise::RegistrationsController
  before_action :configure_account_update_params, only: [:edit, :update]
    protected

  def update_resource(resource, account_update_params)
    resource.update_without_password(account_update_params)
  end

  def after_update_path_for(resource)
    #redirect_to [current_account, resource]
    account_user_path(current_account, current_user)
  end

  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, except: [:current_password, :password])
  end

  def account_update_params
    params.require(:user).permit(:name, :email, :username)
  end

routes.rb

Rails.application.routes.draw do
  devise_for :users, controllers: {
    registrations: 'registrations',
    sessions: 'sessions'
  }
  devise_scope :user do
    get 'login', to: 'users/sessions#new'
    get 'signup', to: 'users/registrations#new'
  end
end

in edit.html.erb

<h3>Edit Profile</h3>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), defaults: {input_html: { class: 'form-control'}, wrapper_html: { class: 'form-group'}}, html: { method: :put }) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>
  <%= f.input :email, as: :email %>
  <%= f.input :username %>
  <%= f.input :name %>

  <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
  <% end %>
  <%= f.button :submit, "Update", class: 'btn btn-primary' %>
<% end %>
<p>
  <h5 class="page-header text-center">Cancel my account</h5>
  <p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger' %></p>
</p>
<p><%= link_to "Home", dashboard_path %></p>

In application_controller.rb

class ApplicationController < ActionController::Base
  set_current_tenant_through_filter
  before_action :find_current_tenant, unless: :devise_controller?
  protect_from_forgery with: :exception
  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :authenticate_user!, unless: :devise_controller?


  protected

  def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up,        keys: [:email, :password, :password_confirmation])
        devise_parameter_sanitizer.permit(:account_update, keys: [:email, :username, :name], except: [:password, :password_confirmation])
        devise_parameter_sanitizer.permit(:sign_in,        keys: [:login, :password])

  end
    ....
    ```

    Any ideas, I've been trying to find an answer to this for a few hours and am stuck and can't seem to find out why Devise continues to ask for a password... Any hints would be great. Thanks!

Posted in Liking Posts Discussion

I finally found the error, it was an error in config/routes.rb. I should have had a singular resource instead of resources, see updated code,

resources :pitches do
      resources :comments, module: :pitches
      resource :likes, module: :pitches, only: [:create, :destroy]
    end

Posted in Liking Posts Discussion

I've got the polymorphic likes working, and even have the ajax version of destroy working, but I can not debug why the create.js.erb isn't working. Rails is telling me I have a routing issue, but rake routes is telling me that I do have this route configured....

Here is the error from development.log

ActionController::UrlGenerationError - No route matches {:account_id=>#<Account id: "def2dbdf-b459-490d-ac41-3f1d1230a1fa", name: "New Co", created_at: "2019-12-28 02:05:01", updated_at: "2019-12-28 02:05:01">, :action=>"destroy", :controller=>"pitches/likes", :pitch_id=>#<Pitch id: 2, title: "Shopability", account_id: "def2dbdf-b459-490d-ac41-3f1d1230a1fa", user_id: "584a1cc3-844d-4b47-9281-dfc520a749b1", created_at: "2019-12-28 23:10:17", updated_at: "2019-12-28 23:10:17">}, missing required keys: [:id]:

Here's my routes...

resources :pitches do
      resources :comments, module: :pitches
      resources :likes, module: :pitches, only: [:create, :destroy]
    end

note: that these are scoped to account ( multitenancy)

I changed the create.js.erb to be a basic alert("create.js.erb called"); but it's not being called. My create method within my pitches::likes controller looks like this,


 def create
    @likable.likes.where(user_id: current_user.id, likable_id: @likable.id).first_or_create
    respond_to do |format|
      format.html { redirect_to [current_account, @likable]}
      format.js {render layout: false}
    end
  end

Any ideas on how to get this to work?