I can't generate a model either migration in rails - ruby-on-rails-3

I have a rails project and i want to add a new table and also make changes in one table which is already in the project.
From the terminal and inside the folder of the existing rails project I write this:
Mini-1:arbinet anna$ rails generate model PriceRate profitable_routes_id:int normalized_rate:float normalized_payout:float margin:float old_rate:float old_payout:float old_margin:float
And also this for the migration:
Mini-1:arbinet anna$ rails generate migration ChangeColumnsFromProfitableRoutes
But for both I get this message:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/anna/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip Git ignores and keeps
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Suppress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
And I don't have any clue why, but it was working when I create the other tables.

You should call the 'rails' command from within the proper docroot (folder) of your app.
So if your app lives in /pub/www/mycoolapp/ you should do: cd /pub/www/mycoolapp/ and run the rails commands from there

A little bin later, but maybe it is a problem that any of you may have.
Run this command inside your app root folder
bundle exec rake rails:update:bin
And enjoy coding!!

Related

Openshift for Play: The remote end hung up unexpectedly

I am trying to launch a play project in openshift. The first phase which was nearly 15% of the project was successfully completed and uploaded. So, I guess the initial configuration was okay. Now, after I completed nearly the rest of the project, then when I am trying to push the project using ssh, everytime after a certain time the remote server hangs up with the following message.
remote: [info] Done packaging.
remote: model contains 69 documentable templates
Connection to blogofprime-thatsqt.rhcloud.com closed by remote host.
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer
To ssh://5455ef32e0b8cd379e000293#blogofprime-thatsqt.rhcloud.com/~/git/blogofprime.git/
+ 557ec12...4034b71 HEAD -> master (forced update)
Every-time after a certain step remote server hangs up.
My openshift.conf file:
# This is the main configuration file for the application.
# ~~~~~
include "application"
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="V0sLX<RAciXw_>7^O8y=I4BRW/M4#vhVhF=H44`lMfgAV2hs^Pp?tsfroKt1J3eX"
# The application languages
# ~~~~~
application.langs="en"
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://"${OPENSHIFT_MYSQL_DB_HOST}":"${OPENSHIFT_MYSQL_DB_PORT}"/"${OPENSHIFT_APP_NAME}
db.default.user=${OPENSHIFT_MYSQL_DB_USERNAME}
db.default.password=${OPENSHIFT_MYSQL_DB_PASSWORD}
# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled
# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default="models.*"
# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .
# Root logger:
logger.root=ERROR
# Logger used by the framework:
logger.play=INFO
# Logger provided to your application:
logger.application=DEBUG
My build.sbt file:
name := "thatsqt"
version := "1.0-SNAPSHOT"
scalaVersion := "2.11.2" // or "2.10.4"
libraryDependencies ++= Seq(
// Select Play modules
jdbc, // The JDBC connection pool and the play.api.db API
//anorm, // Scala RDBMS Library
javaJdbc, // Java database API
javaEbean, // Java Ebean plugin
javaJpa, // Java JPA plugin
filters, // A set of built-in filters
javaCore, // The core Java API
// WebJars pull in client-side web librarie
"org.webjars" %% "webjars-play" % "2.3.0",
"com.typesafe.play" %% "play-slick" % "0.8.0",
// Add your own project dependencies in the form:
// "group" % "artifact" % "version"
"mysql" % "mysql-connector-java" % "5.1.27"
)
fork in Test := false
lazy val root = (project in file(".")).enablePlugins(PlayJava)
EclipseKeys.withSource := true
Platform:
I am using Mac OS X and typesafe activator for play framework.
What I tried:
I tried to unset TMOUT in both server and client. At this point I am not very sure whether this is a timeout problem or something else.
My project Link: https://github.com/magurmach/PlayOpenshiftThatsQt
How can I solve this problem?
If the problem started occurring recently, it may be caused by exceeded quota.
It's very common to run out of space using 1GB small gears.
Try using rhc app-tidy rhc command:
rhc app-tidy <app>
Does your project include large binary files? This can cause git to take up a lot of RAM server-side, and a small Openshift gear will kill things that take too much RAM. The solution is to ssh into your Openshift box (using "rhc ssh" or equivalent) and tell the server-side git to limit its RAM use:
cd git/*.git
git config pack.windowMemory "25m"
git config pack.packSizeLimit "25m"
git config pack.threads "1"
and why they didn't do that by default I have no idea.
Also, next time you want to put large binary files into your project, you don't have to check them into the git repository (which will take up space tracking their entire history): you could just instruct your app to download them from another server as needed (the second server needs only the ability to host static files).

How to set PATH variable in crontab via whenever gem

Is it possible to set the PATH or SHELL variable in a crontab via the whenever schedule.rb file?
# here I want to set the PATH and SHELL variable somehow
every 3.hours do
# some cronjob
end
I want this output in my crontab after my capistrano deploy:
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
# some cronjobs
Ok, it seems as I found the solution. I found it here: https://gist.github.com/jjb/950975
I will update this answer when I have tested it
I have to put this into my schedule.rb
# If your ruby binary isn't in a standard place (for example if it's in /usr/local/bin,
# because you installed it yourself from source, or from a thid-party package like REE),
# this tells whenever (or really, the rails runner) where to find it.
env :PATH, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
You are already doing it when running zenity when setting DISPLAY, LANG etc.
If you want to set the shell, set it in the first line of /home/username/script/script1.sh using #!/bin/bash.
If you want to set the path, one way to do it is to set it before running the command:
5 9-20 * * * PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11 /home/username/script/script1.sh > /dev/null
A alternate/better way is to create a simple wrapper script like so:
#!/bin/bash
export PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
# Absolute path to this script
SCRIPT=`readlink -f $0`
# Absolute directory this script is in
SCRIPTPATH=`dirname $SCRIPT`
#make sure we are in the same directory as the script1.sh - this is useful in case the script assumes it is running from the same directory it's in and makes relative directory/file references
cd $SCRIPTPATH
##run final script, and pass through all parameters that were passed to wrapper script.
/home/username/script/script1.sh "$#"

rails console list directory

I am trying to load a script into Rails console. In order to load the file, I need to do something like:
load scripts/my_script.rb
# This doesn't work... gives this error:
NameError: undefined local variable or method `scripts' for main:Object
load ./scripts/my_script.rb
ArgumentError: wrong number of arguments (0 for 1)
load "./scripts/my_script.rb"
LoadError: cannot load such file -- ./scripts/my_script.rb
# I feel like supermode. Tell me whyyy?
I suspect that I start off in my base rails directory, so if Rails console's "ls" command did as the terminal did (it doesn't), it would list:
app/
config/
scripts/
Gemfile
etc
What commands can I use from within Rails console to navigate around, list the contents of the current directory, and reveal what directory Rails console is currently in?
Or if this is not possible, please spare my sanity and explain why the load command with the directory and filename (and permutations) are not working.
Extra note: I need to reload different files as I make changes to them - so starting the console passing a single filename is no good.
Do you want to do some operations on some ruby files from console?
You can use
Dir.pwd
to get current Directory, and can use other File related methods to require a file.

Provisioning server with Puppet, deploying with Capistrano

I'm having issues with provisioning a server via Puppet that is compatible with a Capistrano deployment. I'm using puppetlabs/apache to setup my virtualhosts, and it is (rightfully) checking that the docroot exists (and creating it if it doesn't, ignoring potential nested directory issues). However, the true docroot will be /var/www/vhosts/${::fqdn}/current/public, and Capistrano will be creating the appropriate symlink (from current to releases/{releasestamp}) when deploying, and is not happy when that directory path is setup by Puppet in advance (due to current being an actual directory, instead of a symlink, and not being empty).
I've thought about adding something like:
file { "/var/www/vhosts/${::fqdn}/current":
ensure => 'link',
target => '/tmp/initial'
}
and setting up a blank file at /tmp/initial/public/index.html, so that Capistrano will be able to point current to the appropriate release when deploying. However, this means that whenever someone re-runs the provision (to apply any configuration changes, for example), the symlink will be relocated to the junk directory (if it even exists at that point).
Any suggestions? I've considered splitting the provision into an application provision and server provision, and having Capistrano execute the application provision when deploying, but I'd really prefer to keep this concise.
You should just use Puppet to create the application directory, and let Capistano take care of creating the releases and shared directories using the cap deploy:setup task, and laying down the current symlink when deploying a new version with cap deploy.
In more concrete terms, I recommend having this in your Puppet config:
file { "/var/www/vhosts/${::fqdn}":
ensure => 'directory'
}
Then, as a one-time setup step, run this task to instruct Capistrano to create the releases and shared directories within the /var/www/vhosts/${::fqdn} directory Puppet should have created for you:
cap deploy:setup
And thereafter, simply run cap deploy to deploy your app, which will create or update the current symlink for you.
(Note that you can pass the -n option to cap to preview the exact commands Capistrano will run, For instance, cap -n deploy:setup will show the mkdir commands it runs.)
Updated
Puppet's standard Apache module seems to require that docroot exist, which it does using the following:
# This ensures that the docroot exists
# But enables it to be specified across multiple vhost resources
if ! defined(File[$docroot]) {
file { $docroot:
ensure => directory,
owner => $docroot_owner,
group => $docroot_group,
}
}
But you may be able to disable that using the following:
file { "/var/www/vhosts/${::fqdn}/current/public":
ensure => directory,
replace => false, # don't replace the directory once Capistrano makes it a symlink
}
Just defining the resource yourself may prevent the if ! defined(File[$docroot]) part of the apache::vhost module from running.
Stuart,
Thanks for the great answer. I found that I had to amend it slightly to put the replace => false on the 'current' directory, not the 'current/public' directory, like so (using a vagrant owner):
file {
'/home/vagrant/app/current':
ensure => directory,
replace => false,
owner => vagrant,
group => vagrant,
}

How do I install this service_wrapper for mongrel/rails on my windows server?

I have been given the unpleasant task of installing a Rails 3 app I have written on Windows Server 2008 (definitely not my choice - was promised a linux server but I.T. pulled the rug out at the last minute so please don't suggest a change in environment as a solution).
I followed the instructions on this blog post (with a few minor modifications) and now actually have my app up and running under Windows/IIS (proxying mongrel) after a great deal of frustration. The only thing remaining is to get mongrel running as a service.
Unfortunately the mongrel gem has not been kept up-to-date for Rails 3 and while I can get the app running under mongrel at the command line I am unable to use mongrel_service to get the app running as a service.
The solution to this appears to be to use the service_wrapper project on github which has been mentioned in this previous question. The project is not yet complete but apparently functional but comes without documentation/binaries. I have looked through the source-code and don't really understand what is it/how it works so was wondering if someone can point me in the right direction (or, even better, walk me through how) to get this installed.
So close, yet still so far.....
Alright I have this worked out (with a little help from luislavena himself - thanks).
Download service_wrapper-0.1.0-win32.zip from https://github.com/luislavena/service_wrapper/downloads and extract service_wrapper.exe from bin/. I extracted it to C:\service_wrapper.
Next set up a configuration file. I used the hello example and modified it for my app then placed it in the C:\service_wrapper directory.
; Service section, it will be the only section read by service_wrapper
[service]
; Provide full path to executable to avoid issues when executable path was not
; added to system PATH.
executable = C:\Ruby192\bin\ruby.exe
; Provide there the arguments you will pass to executable from the command line
arguments = C:\railsapp\script\rails s -e production
; Which directory will be used when invoking executable.
; Provide a full path to the directory (not to a file)
directory = C:\railsapp
; Optionally specify a logfile where both STDOUT and STDERR of executable will
; be redirected.
; Please note that full path is also required.
logfile = C:\railsapp\log\service_wrapper.log
Now just create the service with
sc create railsapp binPath= "C:\service_wrapper\service_wrapper.exe C:\service_wrapper\service_wrapper.conf" start= auto
(watch for the spaces after binPath= and start=. It won't work without them)
Then start it with
net start railsapp
And you're home and hosed!
I ought to contribute due to this article. For config of using bundle exec, use the following:
Note that I am setting up rubyCAS! it's a great OpenCAS authentication mechanism!!!
; Service section, it will be the only section read by service_wrapper
[service]
; Provide full path to executable to avoid issues when executable path was not
; added to system PATH.
executable = C:\Ruby\bin\ruby.exe
; Provide there the arguments you will pass to executable from the command line
arguments = D:\rubycas-server bundle exec rackup -s mongrel -p 11011
; Which directory will be used when invoking executable.
; Provide a full path to the directory (not to a file)
directory = D:\rubycas-server
; Optionally specify a logfile where both STDOUT and STDERR of executable will
; be redirected.
; Please note that full path is also required.
logfile = D:\rubycas-server\log\service_wrapper.log