comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.73k stars 640 forks source link

ArgumentError in url_for in Comfy admin partials after deploy #875

Closed chiubaka closed 5 years ago

chiubaka commented 5 years ago

Expected behavior

After installing and creating migrations, pushing CMS configurations to a remote server should result in a correctly configured CMS instance.

Actual behavior

image When attempting to access the CMS admin area, I get errors like the above.

Steps to reproduce

I deployed a healthy working local configuration of Comfy to a Dev instance backed by AWS Elastic Beanstalk. I expected to be able to configure the first site in the admin area as normal, but was greeted by this instead.

System configuration

Rails version: 5.2.2

CMS version: 2.0.0

Ruby version: Local: 2.5.1p57 Server: 2.5.3p105

chiubaka commented 5 years ago

Been tearing my hair out over this one for a few days! routes.rb does include

  comfy_route :cms_admin, path: "/admin"
  # Ensure that this route is defined last
  comfy_route :cms, path: "/cms"

at the end.

GBH commented 5 years ago

Does it work normally locally? Line that's causing the issue is this: https://github.com/comfy/comfortable-mexican-sofa/blob/master/app/views/comfy/admin/cms/categories/_index.html.haml#L7

That should just generate current url without ?categories param. Nothing special going on here.

Does you app do something weird with url generation in production environment?

chiubaka commented 5 years ago

This does work locally. We're not doing anything special or environment-specific with URL generation on production--they have the same routes.rb file.

Here's the full routes.rb file:

Rails.application.routes.draw do
  namespace :admin do
    resources :press_about_us_links
  end

  scope path: "app" do
    # Devise Routes
    devise_for :users,
               # Override default controllers to Users Controllers
               controllers: {
                 confirmations: "users/confirmations",
                 registrations: "users/registrations",
                 sessions: "users/sessions"
               }

    devise_scope :user do
      post "/users/confirmation" => "users/confirmations#resend"
      patch "/users/confirmation" => "users/confirmations#confirm"
    end

    scope path: "verifications" do
      get "authentication_failed" => "verifications#authentication_failed"
    end
    resources :verifications

    resources :profiles

    # For Incident Form controllers
    resources :incidents, only: %i[new edit show] do
      resources :steps, controller: "incidents/steps", except: [:destroy]
    end

    resources :offenders, except: [:destroy] do
      resources :steps, controller: "offenders/steps", except: [:destroy]
    end

    get "dashboard" => "dashboard#show"
    scope path: "progress" do
      get "welcome" => "progress#welcome"
      get "offender_completion" => "progress#offender_completion"
      get "incident_completion" => "progress#incident_completion"
      get "wait_for_connections" => "progress#wait_for_connections"
      get "understood" => "progress#understood"
    end

    authenticated :user do
      root "dashboard#show", as: :authenticated_root
    end

    root to: redirect("/home")
  end

  root to: "marketing#home"
  get "home" => "marketing#home"
  get "what_we_do" => "marketing#what_we_do"
  get "take_action" => "marketing#take_action"
  get "take_action/human_resources" => "marketing#human_resources"
  get "take_action/anonymous_systems" => "marketing#anonymous_systems"
  get "take_action/audit_committee" => "marketing#audit_committee"
  get "take_action/eeoc" => "marketing#eeoc"
  get "take_action/attorneys" => "marketing#attorneys"
  get "take_action/law_enforcement" => "marketing#law_enforcement"
  get "take_action/professional_associations" => "marketing#professional_associations"
  get "resources" => "marketing#resources"
  get "answers" => "marketing#answers"
  get "about" => "marketing#about"
  get "about/contact" => "contact#show"
  post "about/contact" => "contact#create"
  get "about/press" => "marketing#press"
  get "about/press/about_us" => "marketing#press_about_us"
  get "about/media" => "marketing#media"
  get "privacy_policy" => "marketing#privacy_policy"
  get "terms_and_conditions" => "marketing#terms_and_conditions"
  get "security" => "marketing#security"

  comfy_route :cms_admin, path: "/admin"
  # Ensure that this route is defined last
  comfy_route :cms, path: "/cms"
end
GBH commented 5 years ago

It's not the issue with routes file. Something is going on with url_for helper. Googling around suggests that might be a thing if routing helpers are explicitly included somewhere. The fact that it works in development suggests that there's an environment-based code that does something odd.

chiubaka commented 5 years ago

Interestingly, it turns out that this also doesn't work on any of my colleagues' local environments. It's still not clear to me why... somehow there's something special about my local environment. So far don't have any good leads--I thought if I wiped my DB and tried again that I'd be left with the error, but that didn't work.

chiubaka commented 5 years ago

I do have a mailer where I included the url_helpers... I don't have a good understanding of why these would be related, but I suppose it's worth seeing what happens if I remove it.

include Rails.application.routes.url_helpers

class Users::Mailer < Devise::Mailer
  layout "transactional_email"

  def devise_mail(record, action, opts={})
    initialize_from_record(record)
    mail(headers_for(action, opts)) do |format|
      format.text
      format.html
    end
  end
end
GBH commented 5 years ago

I don't know much about Devise mailers, but in regular Rails mailers you don't need to include route url helpers as mailer views are treated like normal views. The only catch is defining a host.

Also, if you are including, make sure it's inside the mailer class. Right now you basically including them into the global namespace. Who knows what weird things that does.

chiubaka commented 5 years ago

Cool, yeah, I think this somehow had something to do with that include line. Removing it appears to have gotten us to a good place across all environments. Thanks for the help!!