Comments (10)
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.
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 method
workorder_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.
Are you sure you have a tenant set on Heroku?
from acts_as_tenant.
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.
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.comDave
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.
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:in
class: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.
This a pic of the tenant record and the browser when crashed.
from acts_as_tenant.
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.
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.
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)
- User can access everything (admin) HOT 1
- I want to set config.require_tenant to false when the path is /admin, but it doesn't work. HOT 3
- Find Subdomain or Domain, prefer Domain First? HOT 1
- require_tenant set in initializer; not able to use ::with_tenant block without throwing NoTenantSet exception
- avoiding Postgres bitmap heap scans HOT 2
- How to set user before require_tenant check? HOT 1
- Is there a way to disable in the console? HOT 2
- No need to based on Rails MVC HOT 2
- Saving wrong tentant when using factory bot
- Enabling eager_loading causes NoTenantSet error HOT 3
- Gotcha & workaround when using require_tenant = true with ActionMailer::Preview's HOT 5
- Best practice for job queues? HOT 2
- Documentation issue with README.md spotted a mistake HOT 1
- Question: Migration to CurrentAttributes. HOT 2
- ActiveJobExtensions clobbers Sidekiq tenancy HOT 2
- Tenant ID overriden when saving without notice
- ActsAsTenant unexpectedly blocks generation of ActiveStorage representation HOT 5
- Issues with default_url_options HOT 5
- Change to CurrentAttributes leads to broken ActiveJob testing
- `NoTenantSet` error raised within an `ActsAsTenant.without_tenant` block (RSpec + Rails) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acts_as_tenant.