rails 3 rake task link - rake

I tried to link a rake task from a menu but I couldn't, as I explained in the question Rails 3 link_to rake task
but It doesn't work for me. That produces the error uninitialized constant MyTasksController::Rake
any idea?
thanks a lot for you help!

I finally could do it by this way:
class MyTasksController < ApplicationController
def rake_it
system ('rake backup:db:mysql')
redirect_to :action => 'index', :controller => '/events'
end
end

Related

JRuby JDBC setup for rake db:migrate task

I had a ruby Sinatra app and gem pg to use some Java open source applications, I switched to jruby. This is the output for jruby -S rake db:migrate.
NoMethodError: undefined method `get_oid_type' for #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x294f9d50>
api/tasks/db.rake:18:in `block in (root)'
rake file
require 'active_record'
require 'jdbc/postgresql'
namespace :db do
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql:db_name',
:username => 'username',
:password => 'password'
)
end
desc 'Migrate the MOT core models (options: VERSION=x, VERBOSE=false)'
task :migrate => :environment do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : nil
end
desc 'Rolls the schema back to the previous version of MOT core model(specify steps w/ STEP=n).'
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
ActiveRecord::Migrator.rollback "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : step
end
end
db.rake:#18
ActiveRecord::Migrator.migrate "#{File.dirname(FILE)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : nil
I am running postgresql with jdbc.
UPDATE
I add the postgresql.jar to my jruby path (jruby installed by brew in my mac) and I am getting the same error. I also removed the jar file and I had driver not found error.
Thanks for your help.
simply use adapter: postgresql in your configuration and it should work just fine.
I found the solution.
First make sure you have the followings in your Gemfile
gem 'activerecord-jdbc-adapter', :require => 'arjdbc'
gem 'activerecord-jdbcpostgresql-adapter'
then in your db migrate task this is the setup for environment:
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbcpostgresql',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql://localhost/YOUR_DATABASE_NAME'
)
end
Also this is the database.yaml for development:
development:
adapter: jdbcpostgresql
driver: org.postgresql.Driver
encoding: unicode
url: jdbc:postgresql://localhost/YOUR_DATABASE_NAME
username: USER_NAME
password: PASSWORD
Enjoy your JDBC with Jruby on Sinatra application !!!!

cucumber test gives error - Selenium::WebDriver::Error::JavascriptError

i have a tinymca's iframe inside my page and i want to fill_in that tinymca editor with the cucumber test. whenever i run my test it gives me error that jQuery not defined
in my Gemfile
source 'http://rubygems.org'
ruby '2.0.0'
gem 'capybara'
gem 'capybara-mechanize', :git => 'git://github.com/JerryWho/capybara-mechanize.git', :branch => 'relative-redirects'
gem 'rspec'
gem 'cucumber'
gem 'launchy'
gem 'pry'
gem 'selenium-webdriver'
here is my scenario
Scenario: admin puts all the valid and require data
when Job added with all the valid and require data
Then I should see the success message.
and here is the steps for that test
Given(/^I am logged in as a company admin$/) do
visit('/')
fill_in "log", :with => "admin#email.com"
fill_in "pwd", :with => "password"
click_button "submit"
end
When(/^Job added with all the valid and require data$/) do
visit('/site/admin/posts/add/')
within_frame 'questiontextarea_ifr' do
page.execute_script("jQuery(tinymce.editors[0].setContent('my content hersssssssssse'))")
end
click_button "Save"
end
Then(/^I should see the success message\.$/) do
page.should have_content('Success Your post has been successfully added.')
end
but it gives me error jQuery is not defined (Selenium::WebDriver::Error::JavascriptError)
It's most likely because "jQuery is not defined", as the message suggested.
Please try call without jQuery, but with native TinyMCE API:
page.execute_script("tinyMCE.activeEditor.setContent('my content hersssssssssse')")
Further reading: Test WYSIWYG editors using Selenium WebDriver in pure Ruby (not Capybara)

Capistrano: disable db:migrate

How do you disable db:migrate when doing a cap deploy:cold with Capistrano?
In config/deploy.rb the only reference to deploy:migrate is commented out but it's still attempting to do:
bundle exec rake RAILS_ENV=production db:migrate
I got success by overriding the deploy:migrate method in my config/deploy.rb.
namespace :deploy do
desc "No ActiveRecord override"
task :migrate do
end
end
When re-defining a task in Capistrano v2, the original task was replaced. However the Rake DSL on which Capistrano v3 is built is additive. According to documentation.
Under most circumstances, you will simply want to use clear_actions, which removes the specified task’s behaviour, but does not alter it’s dependencies or comments:
namespace :deploy do
Rake::Task["migrate"].clear_actions
task :migrate do
puts "no migration"
end
end
I had the same problem. That's why I override it in the Rakefile. Like this:
namespace :db do
desc "db:migration fakes"
task :migrate => :environment do
p 'No. We will not migrate!'
end
end
Here you can add more logic if you like. You could for example trigger a real migration on certain environments.

Ruby on Rails Tutorial 3.2 by Michael Hartl Chapter 9. authentication_pages_spec.rb doesn't see sign_in method in utilities.rb

This is my first question on StackOverflow, so bear with me ...
When I use the authentication_pages_spec.rb in Listing 8.6 my tests pass.
Then I define the sign_in method in 'spec/support/utilities.rb' and modify authentication_pages_spec.rb according to Listing 9.5 and, when running
$ bundle exec rspec spec/requests/authentication_pages_spec.rb -e "Authentication"
I get
1) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_2:0x007fc585a87cd8>
# ./spec/requests/authentication_pages_spec.rb:31:in `block (4 levels) in <top (required)>'
for all the six tests under "with valid information".
It seems that the spec doesn't see the sign_in function and needs some declaration, anyhow I couldn't find where this is done in the Michael Hartl's code on Github.
Any help is really appreciated.
Just Restart spork and it should work :)
Hartl explains the sign_in helper almost immediately after that in Listing 9.6
I encountered the exact same error messages, based on a subtle mis-placement of an end. Sharing here, in case others run into the same test failures and are seeking a possible solution.
My mistake was in how I authored utilities.rb, which was:
include ApplicationHelper
RSpec::Matchers.define :have_error_message do |message|
match do |page|
page.should have_selector('div.alert.alert-error', text: 'Invalid')
end
def sign_in(user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
# # Sign in when not using Capybara as well.
# cookies[:remember_token] = user.remember_token
end
end
What the final end needs to be after the RSpec::Matchers block and should read like this:
include ApplicationHelper
RSpec::Matchers.define :have_error_message do |message|
match do |page|
page.should have_selector('div.alert.alert-error', text: 'Invalid')
end
end
def sign_in(user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
# # Sign in when not using Capybara as well.
# cookies[:remember_token] = user.remember_token
end

FOSFacebookBundle - FacebookSessionPersistence - Fatal error: Class 'BaseFacebook' not found

I'm using FOSFacebookBundle on symfony2.
I would like to create an object from FacebookSessionPersistence to read facebook User Informations.
But i have the following error:
Fatal error: Class 'BaseFacebook' not found in C:\Users\gp\Desktop\xampp\htdocs\projectOne\p1\vendor\bundles\FOS\FacebookBundle\Facebook\FacebookSessionPersistence.php on line 13
I registered the bundle and the autoloader like in the installation document.
Has anybody an idea what I'm doing wrong?
Thanks
1.) are you sure you have facebook sdk also installed?
[FacebookSDK]
git=git://github.com/facebook/php-sdk.git
target=/facebook
2.) Are you sure you have config set?
fos_facebook:
file: %kernel.root_dir%/../vendor/facebook/src/base_facebook.php
Check your autoload_classmap.php file, it should contain something like this
'BaseFacebook' => $vendorDir . '/facebook/php-sdk/src/base_facebook.php',
'Facebook' => $vendorDir . '/facebook/php-sdk/src/facebook.php',
'FacebookApiException' => $vendorDir . '/facebook/php-sdk/src/base_facebook.php',
if you installed the "facebook/php-sdk" with composer, it should be done automatically.