How would I create the following scenario that rails can provide for carrierwave, using sinatra:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
... being able to store an avatar under a directory named using the model ID.
Should have checked the wiki:
https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-a-fast-lookup-able-storage-directory-structure
Related
I use now persistenceMapperWEBAPIClient1 as PersistentMapper with default Uri http://localhost:5000/api/A0_WebApi and default User: a/Password: 123456
While prototyping on Local Server I have saved some data for the same(default) user.
Now I start my application with persistenceMapperWEBAPIClient1 as PersistentMapper, but I get no data. So it seems I access quite different data from prototype and from my application. Is it a thing of prefix perhaps? But I use the same user in both cases
/Efim
That is the answer of Hans:
The turnkey application can either go in prototype mode - then it saves to a xml file named as the model - controlled by App_Data/MDrivenServerOverride.xml
...or it can connect to an MDriverServer in one of two ways:
MDrivenServer is found relative to TurnkeyApp ./__MDrivenServer and user and pwd taken from App_Data/TurnkeySettings.xml
MDrivenServer is found from setting in App_Data/MDrivenServerOverride.xml :
http://localhost:5010/
https://wiki.mdriven.net/index.php/MDrivenServerOverride
/Hans
I would like to add comments on objects such as database itself, tables, etc while using rake. For example, when I issue rake db:create I'd like to automagically add a comment via PostgreSQL extended SQL statement (if the adapter doesn't support this directly), like
COMMENT ON DATABASE myapp_development IS 'Rails DB for project at c:/some/path/myapp/';
I'd like a similar behavior for ActiveRecord::Migration, if possible (by extracting RDoc?) for tables and columns.
It occurs to me that this may be more like a feature request rather than something that could be done quickly. Is this already possible to do, and how can I do it?
You should be able to just execute the raw SQL where you need it. Try this:
sql = "COMMENT ON DATABASE myapp_development IS 'Rails DB for project at c:/some/path/myapp/';"
records_array = ActiveRecord::Base.connection.execute(sql)
Note that you can use string interpolation (e.g. "#{value}") to include variable values if you need. You have all the expressive power of Ruby and the ability to run any native SQL that you need.
The MigrationComments gem gives inline support for comments on migration objects. To install it, simply add this to your Gemfile:
gem 'migration_comments'
Once installed, you can include both inline comments:
def self.up
create_table :users, comment: "User records are stored in this table." do |t|
t.string :canonical_email, comment: "This column contains the email address that has been URL decoded and lowercased, to ensure system-wide uniqueness"
end
end
and standalone comment changes:
def self.up
change_table :users do |t|
t.comment "User records are stored in this table."
t.change_comment :canonical_email, "This column contains the email address that has been URL decoded and lowercased, to ensure system-wide uniqueness"
end
end
You can find the PgComment gem that will give you commenting with an ActiveRecord-like syntax. Simply add this to your Gemfile:
gem 'pg_comment'
And you'll be able to do cool things like this:
set_table_comment :users, "User records are stored in this table."
set_column_comment(:users, :canonical_email, "This column contains the email address that has been URL decoded and lowercased, to ensure system-wide uniqueness")
Unfortunately, there's no set_database_comment with either gem, so database comments (and other unsupported Postgres objects) would require use of the raw SQL solution shown at the top of the answer.
It turned out it is easier than I thought. One can create ./lib/tasks/annotate_db.rake, e.g., from Rails template file, with the following content
namespace :db do
def update_db_comment
Rails.configuration.database_configuration.each do |key, hash|
db = hash['database']
if not db.nil?
sql = "COMMENT ON DATABASE #{db} IS 'Rails #{Rails::VERSION::STRING} #{key} DB for project at #{Rails.root} on #{Socket.gethostbyname(Socket.gethostname).first}';"
# puts sql
records_array = ActiveRecord::Base.connection.execute(sql)
end
end
end
task :create do
update_db_comment
end
end
# Rake::Task['db:create'].enhance(['db:set_db_comment'])
Following my upgrade from OrientDB 2.1.16 to 2.2.0 I have started to get the following messages during the initialisation:
2016-05-19 09:28:38:690 SEVER ODefaultServerSecurity.loadConfig() Could not access the security JSON file: /config/security.json [ODefaultServerSecurity]
2016-05-19 09:28:39:142 SEVER ODefaultServerSecurity.onAfterActivate() Configuration document is empty [ODefaultServerSecurity]
The database launched but I don't like the warnings. I've looked through the docs but I cant find anything specifically pertaining to this. There are some links on Google that lead to dead Github pages.
First of all I need to get hold of either a copy of the security.json it is expecting (or the docs explaining the expected structure).
Secondly I need to know how and where to set it.
There are 3 ways to specify the location and name of the security.json file used by the new OrientDB security module.
1) Specify the environment variable, ORIENTDB_HOME, and it will look for it here:
"${ORIENTDB_HOME}/config/security.json"
2) Set this property in the orientdb-server-config.xml file: "server.security.file"
3) Pass the location by setting the global variable -Dserver.security.file on startup.
Here's the documentation on the new features + a link to the configuration format.
https://github.com/orientechnologies/orientdb-docs/blob/master/Security-OrientDB-New-Security-Features.md
-Colin
OrientDB LTD
The Company behind OrientDB
In a Play 2.1 application, where is the proper place to store private assets?
By "private asset", I mean a data file that is used by the application but not accessible to the user.
For example, if I have a text file (Foo.json) that contains sample data that is parsed every time the application starts, what would be the proper directory in the project to store it?
Foo.json needs to be included in the deployment, and needs to be uniformly accessible from the code in both development and production.
Some options:
Usually the files goes to conf folder. ie: conf/privatefiles/Foo.json
If they are subject of often change you can consider adding to your application.conf path to the external folder somwhere in the filesystem (full path), in such case you'll be able to edit the content easily without redeploying the apps: /home/scrapdog/privatefiles/Foo.json
You can store them in database as well, benefits are the same as in previous option - easy editing.
In all cases consider using memory cache to avoid reading it from filesystem/database every time when required.
I simply use a folder called data at the application root. You can use the name you want or better, store the actual name in the configuration file.
To resolve its path, I use the following snippet:
lazy val rootPath = {
import play.api.Play.current
play.api.Play.application.path.getPath
}
lazy val dataPath = rootPath + "/data/"
You can do what I did, I got the answer from #Marius Soutier here. Please upvote his answer there if you like it:
You can put "internal" documents in the conf folder, it's the equivalent to resources in standard sbt projects.
Basically create a dir under conf called json and to access it, you'd use Play.resourceAsStream(). Note that this gives you a java.io.InputStream because your file will be part of the JAR created by activator dist.
My example is using it in a view but you can modify it as you want.
Play.resourceAsStream("json/Foo.json") map { inputStream =>
Ok(views.html.xxx(XXX.do_something_with_stream(inputStream)))
} getOrElse (InternalServerError)
You can also use Play.resource(), this will give you a java.net.URL, you can use getFile() to get the java.io.File out of it.
Play.resource("json/Foo.json") map { fileURL =>
Ok(views.html.xxx(XXX.do_something_with_file(fileURL.getFile())))
} getOrElse (InternalServerError)
I have a iPhone project where i use frank and cucumber for acceptance testing.
My application has a feature to collect files from the documents directory and index them in the applications database.
I want to test this feature with cucumber. But this means i have to copy files to the applications documents directory.
My questions are:
How do i dynamically make step definitions to copy files?
Where do place the resources before they get copied? In what folder structure?
How do i reach these files from my step definitions?
Thanks.
We created a helper function to do something like this for injecting images into the simulator gallery..
def init_simulator_images(num_images)
(1..num_images.to_i).each do |n|
target_file = "IMG_000#{n}.JPG"
begin
File.stat("#{ENV['simulator_media_path']}/#{target_file}")
rescue Errno::ENOENT
app_exec 'FEX_loadPhotoLibraryImage:', "test/#{target_file}"
end
end
end
and then on the native code side, we have a helper class called FEX_Helper to aid in anything where we need to modify the app at runtime (RubyMotion code but v. similar to objective-c except for the syntax):
def FEX_loadPhotoLibraryImage(imageStr)
img = UIImage.imageNamed(imageStr)
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil)
end
Lastly the simulator media path is defined thusly:
def simulator_media_path
"#{self.simulator_version_path}/Media/DCIM/100APPLE"
end
def simulator_path
"/Users/#{self.user}/Library/Application\ Support/iPhone\ Simulator"
end
def simulator_version_path
"#{self.simulator_path}/#{self.simulator_version}"
end
Hope that helps someone trying to inject files into the simulator for testing.
Mark