Google App Engine Rails Template

Hi Christian

Thanks for the code sample.

I am very eager to use a standard Ruby development environment for App
Engine without restarts as you have described.

I have spent several hours trying to use your code sample to configure a
Rails project with GAE but so far have been unsuccessful.

Have you made any other significant changes to your Rails app besides
what
you mentioned?

Thanks,
Carson

I haven’t played with it lately so I need to recall…

Well, first of all my dev environment is not a real AppEngine setup,
it’s plain JRuby/Rails plus Datastore. That’s all I have used so far (no
memcache or mailer). One thing you need to do is require the
appengine-api-1.0-sdk-1.2.1.jar to make the AppEngine stuff available.
I’ve put the jar in the lib folder and require it in
config/development.rb.

I think that’s all. By the way, I used this example as project template:
http://github.com/nicksieger/jruby-rack/tree/bb907c03c48eb999e7d099068245b91eeda545bf/examples/rails

I hope this helps!

Carson Welsh wrote:

From: *Christian S.* <[email protected]
 if Rails.env=='development'
     import com.google.appengine.tools.development.ApiProxyLocalImpl
       ApiProxy.delegate = Class.new(ApiProxyLocalImpl).new
   end
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Christian,

I wonder if you have any idea what might be going wrong here. I
downloaded
the Nick S. template and added your addition to the
application_controller.rb, added the appengine-api-1.0-sdk-1.2.1.jar to
the
lib folder and require it in config/development.rb. But I get the
following
error after I start the application:

NameError in SnoopController#index

cannot load Java class
com.google.appengine.api.datastore.dev.LocalDatastoreService

RAILS_ROOT: C:/wsp/siegerails/examples/rails

Application Trace | Framework Trace | Full Trace
C:/jr/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:87:in
get_proxy_or_package_under_package' C:/jr/lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:51:inmethod_missing’
C:/wsp/siegerails/examples/rails/app/controllers/application_controller.rb:20
C:/wsp/siegerails/examples/rails/app/controllers/application_controller.rb:380:in
load' C:/wsp/siegerails/examples/rails/app/controllers/snoop_controller.rb:1 C:/wsp/siegerails/examples/rails/app/controllers/snoop_controller.rb:380:inload’

Thanks. Cleared that hurdle.

Now the error I’m getting is inside the code you added to
application_controller.rb:

“wrong # of arguments for constructor” in
application_controller.rb:32:in `setup_datastore’

Looks like the problem is in the second line of the setup_datastore
method.

Did you do any customization here?

Also, probably not related to this error I’m getting but, it looks
like maybe you commented out those two lines beginning with
“ApiProxy”? If so, was there a reason?

def setup_datastore
  ApiProxy.environment_for_current_thread = DevEnvironment.new
  ApiProxy.delegate = Class.new(ApiProxyLocalImpl).new
  java.io.File.new('.')
  #ApiProxy.delegate.set_property

LocalDatastoreService::NO_STORAGE_PROPERTY, ‘true’
end

def teardown_datastore
  #ApiProxy.delegate.get_service('datastore_v3').clear_profiles
  ApiProxy.delegate = nil
  ApiProxy.environment_for_current_thread = nil
end

On Tue, Jun 16, 2009 at 2:45 PM, Christian S. [email protected]
wrote:

NameError in SnoopController#index
`method_missing’
<[email protected] mailto:[email protected]> wrote:

> Thanks for the code sample.
besides
<mailto:[email protected]>
>     (application_controller.rb).
>          import
>
>
>

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Ignore my last message. Sorry.

I had a whitespace mistake on this line:

ApiProxy.delegate = Class.new(ApiProxyLocalImpl).new
java.io.File.new(’.’)

But I’m still curious why those two lines are commented out in
setup_datastore and teardown_datastore.

On Tue, Jun 16, 2009 at 3:31 PM, Carson Welsh[email protected]
wrote:

Did you do any customization here?
LocalDatastoreService::NO_STORAGE_PROPERTY, ‘true’
On Tue, Jun 16, 2009 at 2:45 PM, Christian S. [email protected] wrote:

NameError in SnoopController#index
`method_missing’
<[email protected] mailto:[email protected]> wrote:

> Thanks for the code sample.
besides
<mailto:[email protected]>
>     (application_controller.rb).
>          import
>
>
>

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Forgot about two other jar files:

appengine-api-stubs-1.2.1.jar
appengine-local-runtime-1.2.1.jar

But you shouldn’t put them into the lib folder, because I think Warbler
would pick them up and include them in the war file. You don’t want
these libs on AppEngine.

Carson Welsh wrote:

C:/wsp/siegerails/examples/rails/app/controllers/application_controller.rb:20

I think that's all. By the way, I used this example as project
>
> what you mentioned?
>     <mailto:[email protected] <mailto:[email protected]>>>
>
>     com.google.appengine.api.datastore.dev.LocalDatastoreService
>          def setup_datastore
 #ApiProxy.delegate.get_service('datastore_v3').clear_profiles
>

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

First of all, I really recommend doing your development under the App
Engine dev_appserver. There’s plenty of ways to get automatic
reloading. It sounds like this template already sets up symbolic links
for you. In that case you probably just need to edit you web.xml to
set your environment to development instead of production. Just make
sure you set it back before deploying to production.

Second, if you want to set up a test datastore I suggest using the
AppEngine::Testing module from the appengine-apis gem. The easiest way
is to require ‘appengine-apis/local_boot’. This will add the
necessary jars to your class path and read your appengine-web.xml to
set you up with the same on disk datastore that dev_appserver uses.
It does nothing if things were already configured by dev_appserver or
the prod servers, so it should be fine to just add this to your
environment.rb
You can also call AppEngine::Testing::install_test_datastore if you
want an in-memory datastore for unittests.

– Ryan B.

On Tue, Jun 16, 2009 at 12:38 PM, Carson Welsh[email protected]
wrote:

 #ApiProxy.delegate.set_property

C:/jr/lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:51:in
On Tue, Jun 16, 2009 at 5:12 AM, Christian S.
config/development.rb.
>
> Have you made any other significant changes to your Rails app
> From: Christian S. <[email protected]
> plus setting up the datastore in the controller
> import com.google.apphosting.api.ApiProxy
> end
> def teardown_datastore
> http://xircles.codehaus.org/manage_email
http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

HI I agree with Ryan that it is best to develop under the devserver so
that
there no surprises when you go to deploy. Unfortunately, I have tried
using
development mode with the devserver but it does not work. When Rails
tries
to reload the ruby files it throws a security exception. However if you
make to changes to the production.rb you can atleast get auto reload of
the
HTML and CSS files. Check out http://www.codingforrent.com/posts/7002
for
more details. If you just want a quick answer here is what you need to
change:
config.action_controller.perform_caching = false
config.action_view.cache_template_loading = false

It will not speed up the ruby development, but at least you can use unit
tests to help with that.

Josh M.

Josh,

I just tried Ryan’s suggestion with Ola’s yarbl sample and automatic
reloading seems to be working now. Wish I’d tried this sooner! All I did
was
change “production” to “development” in web.xml.

The line from development.rb that seems to achieve this is this one:

config.cache_classes = false

Just in case you need the rest of Ola’s development.rb for reference,
it’s
here:

http://github.com/olabini/yarbl/tree/master

Thanks, Ryan.

Chris

On Tue, Jun 16, 2009 at 4:02 PM, Josh M.[email protected] wrote:

HI I agree with Ryan that it is best to develop under the devserver so that
there no surprises when you go to deploy. Unfortunately, I have tried using
development mode with the devserver but it does not work. When Rails tries
to reload the ruby files it throws a security exception.

Hmm. I guess I’ve only used automatic reloading with merb. What’s the
error you get from rails?

AppEngine::Testing module from the appengine-apis gem. The easiest way

application_controller.rb:
like maybe you commented out those two lines beginning with
def teardown_datastore

Forgot about two other jar files:
Carson Welsh wrote:

`method_missing’

far (no

> Engine without restarts as you have described.
> Carson
>     To: [email protected]
>
>
>
>          def teardown_datastore
>
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Chris,
When I tried that I got this exception:

SEVERE: [1245197971854000] javax.servlet.ServletContext log: Exception
caught
java.security.AccessControlException: access denied
(java.io.FilePermission
/Users/joshmoore/code/rails_turbine/app/views/layouts/** read)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at
java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at
com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:122)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.isDirectory(File.java:752)
at org.jruby.util.Dir.glob_helper(Dir.java:641)

It seems like the security manager is not allowing the reloading of the
classes. I would be interested in learning how you got around this
exception.

Josh

Josh,

Without seeing your code I’m not sure why you’re getting that. I can
send
you a zip file of my local version of yarbl, which I know is working,
and
you can compare it against your app if you like. I’ll send it to you in
a
moment.

Chris

Carson Welsh wrote:

Did you do any customization here?

Also, probably not related to this error I’m getting but, it looks
like maybe you commented out those two lines beginning with
“ApiProxy”? If so, was there a reason?

http://code.google.com/appengine/docs/java/howto/unittesting.html#Writing_Datastore_Tests

-> describes how to write datastore tests. I took the code and adapted
it to not destroy the data every time (something you want to have in
tests but not in dev mode of course)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks for the link, Christian.