Giter VIP home page Giter VIP logo

Comments (10)

ErwinM avatar ErwinM commented on September 18, 2024

ActsAsTenant.current_tenant will return the current set tenant..

So not sure why your first example is failing. What error are you getting?

The current_tenant helper is only available to the controller, so your second example will not work.

Op 13 feb. 2014 om 15:28 heeft David Burton [email protected] het volgende geschreven:

I have a field called request_closed in my Tenant record.

In the Request model, I would like to be able to use that field.

I tried this:

statusclosed = ActsAsTenant.current_tenant.request_closed
scope :notclosed, where("statuscode_id < ?", statusclosed )

And

statusclosed = current_tenant.request_closed

How can I access a current tenant record in a model?


Reply to this email directly or view it on GitHub.

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024

Thanks for your help@

This code works in development on my Mac:

class Workorder < ActiveRecord::Base
43 $closedcode = ActsAsTenant.current_tenant.workorder_closed

But, when I upload to Heroku, the app crashes with this:

workorder.rb:43:in <class:Workorder>': undefined methodworkorder_closed' for nil:NilClass

Regards,
David Burton

On Feb 13, 2014, at 10:45 AM, ErwinM [email protected] wrote:

ActsAsTenant.current_tenant

from acts_as_tenant.

ErwinM avatar ErwinM commented on September 18, 2024

Are you sure you have a tenant set on Heroku?

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024

Erwin,

Yes.

Here are 2 of the URLs to the same Heroku app (It’s under development):

hosp.ndeavor2s.com
ame.ndeavor2s.com

Dave
On Feb 14, 2014, at 12:40 AM, ErwinM [email protected] wrote:

Are you sure you have a tenant set on Heroku?


Reply to this email directly or view it on GitHub.

from acts_as_tenant.

ErwinM avatar ErwinM commented on September 18, 2024

Could you post the full stack trace of the error?

Groet,
Erwin

Op 14 feb. 2014 om 15:29 heeft David Burton [email protected] het volgende geschreven:

Erwin,

Yes.

Here are 2 of the URLs to the same Heroku app (It’s under development):

hosp.ndeavor2s.com
ame.ndeavor2s.com

Dave
On Feb 14, 2014, at 12:40 AM, ErwinM [email protected] wrote:

Are you sure you have a tenant set on Heroku?


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024

This is the Heroku log:
Feb 18 06:47:50 ndeavor-staging heroku/web.1: State changed from crashed to starting
Feb 18 06:47:57 ndeavor-staging heroku/web.1: Starting process with command bundle exec unicorn -p 4747 -c ./config/unicorn.rb
Feb 18 06:48:03 ndeavor-staging app/web.1: I, [2014-02-18T07:48:02.899741 #2] INFO -- : Refreshing Gem list
Feb 18 06:48:03 ndeavor-staging app/web.1: /app/config/application.rb:3:in <top (required)>': iconv will be deprecated in the future, use String#encode instead. Feb 18 06:48:16 ndeavor-staging app/web.1: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) Feb 18 06:48:16 ndeavor-staging app/web.1: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Starting the New Relic agent in "production" environment. Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : To prevent agent startup add a NEWRELIC_ENABLE=false environment variable or modify the "production" section of your newrelic.yml. Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Reading configuration from config/newrelic.yml Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Enabling the Request Sampler. Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Environment: production Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Dispatcher: unicorn Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Application: My Application Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Connecting workers after forking. Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Unicorn instrumentation Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Detected Unicorn, please see additional documentation: https://newrelic.com/docs/troubleshooting/im-using-unicorn-and-i-dont-see-any-data Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing DelayedJob instrumentation [part 1/2] Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing deferred Rack instrumentation Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing ActiveRecord instrumentation Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Net instrumentation Feb 18 06:48:19 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Resque instrumentation Feb 18 06:48:20 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Rails 3 Controller instrumentation Feb 18 06:48:20 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Rails 3.1/3.2 view instrumentation Feb 18 06:48:20 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Installing Rails3 Error instrumentation Feb 18 06:48:20 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : Finished instrumentation Feb 18 06:48:20 ndeavor-staging app/web.1: ** [NewRelic][02/18/14 07:48:19 -0700 2de21edb-b714-4cc1-b238-95cf9cb05211 (2)] INFO : NewRelic::Agent::Samplers::DelayedJobSampler not available: No DJ worker present Feb 18 06:48:22 ndeavor-staging app/web.1: [DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it. Feb 18 06:48:31 ndeavor-staging app/web.1: /app/app/models/worequest.rb:27:inclass:Worequest': undefined method request_closed' for nil:NilClass (NoMethodError) Feb 18 06:48:31 ndeavor-staging app/web.1: from /app/app/models/worequest.rb:1:in<top (required)>'

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024

This a pic of the tenant record and the browser when crashed.

app error
tenant record

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024
class Worequest < ActiveRecord::Base
  acts_as_tenant(:tenant)  
  statusclosed = ActsAsTenant.current_tenant.request_closed

    scope :notclosed, where("statuscode_id < ?", statusclosed )
    scope :closed, where(:statuscode_id => statusclosed)

from acts_as_tenant.

ErwinM avatar ErwinM commented on September 18, 2024

You could try using a lambda. It might be that statusclosed is only evaluated when the class is loaded. In production this happens when the app boots, in development this happens with every request.

try something like:

scope :closed, -> { where("statuscode_id < ?", ActsAsTenant.current_tenant.request_closed) }

The new lambda / scope syntax still confuses me, so I myself would use:

def self.notclosed
  where("statuscode_id < ?", ActsAsTenant.current_tenant.request_closed)
end

Let me know if this works

from acts_as_tenant.

burtondav avatar burtondav commented on September 18, 2024

Erwin,
The following worked!!

def self.notclosed
where("statuscode_id < ?", ActsAsTenant.current_tenant.request_closed)
end

Thanks for your help!!

Dave
On Feb 18, 2014, at 11:46 AM, ErwinM [email protected] wrote:

def self.notclosed
where("statuscode_id < ?", ActsAsTenant.current_tenant.request_closed)
end

from acts_as_tenant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.