vendredi 8 mai 2015

Gem needs to access project specific folder

I am planning to create a ruby gem project and finally add that library gem in to another project. gem does some extra steps which needs to be completed before project feature file execution. Now i need to access the project feature folder from this gem. I tried this code

feature_folder= File.join("**", "features")
Dir.glob(feature_folder)

but didnt work. Is there anyway i can access the project features folder from my gem? I couldn't find how exactly cucumber access the project folders ( features , step_definitions) from cucumber gem.

Why in ruby, 0.692 * 3 = 2.0759999999999996?

$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

$ irb
irb(main):001:0> 0.692 * 3
=> 2.0759999999999996

I just ran into these numbers by chance. Is this related to Why Are Floating Point Numbers Inaccurate?.

How is it that you can do `Integer('1')` in Ruby?

How does the standard library allow you to coerce a String into an Integer with Integer('1') #=> 1? Is there a language feature that allows one to create this kind of conversion syntax in a class?

Getting a file name instead of directory name in Ruby

PLEASE NOTE THAT I AM A NOOB

So I recently started learning Ruby and a buddy is motivating me to get into it so he helped me get on my way. We're currently building a program that allows you to download the HTML code from a page. My code isn't working. The code is:

require 'net/http'

print "Source: "
source = gets.chomp

print  "Path: "
filename = gets.chomp

page = Net::HTTP.get(source, path) 
path = File.join(File.dirname(__FILE__), filename)
file = File.open(path, 'r+')
file.write(page)
file.close()

and the error message I get is

webdownload.rb:11:in `initialize': Is a directory - ./ (Errno::EISDIR)
from webdownload.rb:11:in `open'
from webdownload.rb:11:in `<main>'

My buddy said it's because I'm declaring a directory name instead of a file name (which I can deduce from the error message). I however don't know how to change it into a file name.

Fixture finder methods

I have two models: User, Group

I have fixtures for both of them.

I have UserTest class which is unitTest and I can use fixture finder users(:someuserfixture). However, if I try to use groups(:somegroupfixture) it says that groups isn't recognized.

How can I access fixtures of another model?

ruby - split an array into sub arrays when a value changes and ignore/delete that value

I want to split the following array into sub arrays so that the sub-arrays start and finish when the 1's start and finish...

a=[1,1,0,0,1,0,1,1,1]

so I end up with this as a new array...

=> [[1,1],[1],[1,1,1]]

anyone got any ideas...?

thanks in advance Matt

Chef, Vagrant and private git cloning

i have acces to git repo on host, and i have a Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu14.04"
  config.vm.box_url = "http://ift.tt/1cwfxmd    vagrant-disk1.box"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 1024
    vb.cpus = 2
  end
  config.ssh.forward_agent = true
  config.vm.provision :chef_solo do |chef|
  # chef.log_level = :debug
    chef.cookbooks_path = "./cookbooks"
    chef.add_recipe "git_sync"
  end
end

if i run vagrant and ssh into it, i could also git clone my private repo, (recipe "install_pkgs" is to install git on vm) but the pecipe "git_sync" gets an error like:

[2015-05-08T18:40:26+00:00] ERROR: Running exception handlers
[2015-05-08T18:40:26+00:00] ERROR: Exception handlers complete
[2015-05-08T18:40:26+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-05-08T18:40:26+00:00] ERROR: git[/home/vagrant/geomongo] (git_sync::default line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
---- Begin output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
STDOUT: 
STDERR: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
---- End output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
Ran git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD returned 128

================================================================================
Error executing action `sync` on resource 'git[/home/vagrant/geomongo]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '128'
---- Begin output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
STDOUT: 
STDERR: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
---- End output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
Ran git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD returned 128


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/git_sync/recipes/default.rb

  1: git "/home/vagrant/geomongo" do
  2:   # repository "git@bitbucket.org:osll/geomongo.git"  
  3:   # repository "http://ift.tt/1cwfxCz"
  4:   repository "git@bitbucket.org:galiaf95/test.git"
  5:   action :sync
  6: end


Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/git_sync/recipes/default.rb:1:in `from_file'

git("/home/vagrant/geomongo") do
  provider Chef::Provider::Git
  action [:sync]
  retries 0
  retry_delay 2
  destination "/home/vagrant/geomongo"
  revision "HEAD"
  remote "origin"
  cookbook_name :git_sync
  recipe_name "default"
  repository "git@bitbucket.org:galiaf95/test.git"
end



[2015-05-08T18:38:31+00:00] INFO: Forking chef instance to converge...
[2015-05-08T18:40:26+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Here is my git_sync.rb recipe

git "/home/vagrant/geomongo" do"
  repository "git@bitbucket.org:galiaf95/test.git"
  action :sync
end

I'm new to chef and vagrant and it would be great to have some very comprehensive examples.

can't download file from google drive with ruby

I'm trying to get my rails controller set up to download a file from google drive following the code at - http://ift.tt/Q3fmNw

I have the following rails code

def download_file(client, file)
  if file.download_url
    result = client.execute(:uri => file.download_url)
    if result.status == 200
      return result.body
    else
      puts "An error occurred: #{result.data['error']['message']}"
      return nil
    end
  end
end

def attachExternalResume
  # read remote url to file
  file_id = params[:fileId]
  client = Google::APIClient.new
  drive = client.discovered_api('drive', 'v2')
  result = client.execute(
    :api_method => drive.files.get,
    :parameters => { 'fileId' => file_id}
  )
  if (result.status == 200)
    p download_file client, result.data
  end
end

This is being called from my javascript front end using the google picker. The user authorizes my app through the google picker and selects a file which results in my angular javascript posting the file id to my rails method. In the rails code I'm getting the following error - Missing access token.

It seems like even though the user has authorized the app on the front end, that authorization isn't making its way through to the rails side. Anyone know how I can get the authorization all the way through the process?

Rails 4 Internationalization I18n

My Rails App is on rails 4.0.2 and I have a problem switching translations with the locale variable and the params[:locale] from the url scheme following the official rails guide. I have a single page website at my site.

My routes for Internationalization:

scope "(:locale)", locale: /en|de/ do
  #my routes here
end

My application controller

before_filter :set_locale
  def set_locale
     I18n.locale = params[:locale] || I18n.default_locale
     #Rails.application.routes.default_url_options[:locale]= I18n.locale
  end

  # app/controllers/application_controller.rb
  def default_url_options(options = {})
     { locale: I18n.locale }.merge options
  end

The links to change the locale variables in the view:

<%= link_to_unless I18n.locale == :en, "English", locale: :en %>
|
<%= link_to_unless I18n.locale == :de, "Deutsch", locale: :de %>

What happens: the locale variable is set correctly but the translations are not switching. If I remove one of the translation files (currently for english and german) the languages switches to the remaining translation file. When I put back the other translation file and try to switch to it by changing the locale variable it never switches to the other language.

Why is my code not changing the translations?

HAML: interpolate ruby variable for data attribute?

In a .html.haml file, I have a button:

%button{:data=>{'foo'=> @bar}, type:'button', 'id'=>'confirmBtn'} Confirm

However, the data attribute is not picking up anything. What is the proper way to interpolate ruby variables in this case?

Q: How to edit file content using zsh terminal?

I created an empty directory on zsh and added a file called hello.rb by doing the following:

echo 'Hello, world.' >hello.rb

If I want to make changes in this file using the terminal what's the proper way of doing it without opening the file itself using let's say TextEditor?

I want to be able to make changes in the file hello.rb strictly by using my zsh terminal, is this at all possible?

Ruby ancestry gem official documentation

I am new to Ruby. Apart from this one, is there any other structured/official documentation for 'ancestry' gem?

What does this code, that looks like JavaScript object do?

@options = { query: {site: service, page: page} }

What does this do? In javascript this, I think would be object definition, however I cannot find what exactly it is in ruby. This would be the full code:

class StackExchange
  include HTTParty
  base_uri 'api.stackexchange.com'

  def initialize(service, page)
    @options = { query: {site: service, page: page} }
  end

  def questions
    self.class.get("/2.2/questions", @options)
  end

  def users
    self.class.get("/2.2/users", @options)
  end
end

Rails delete functionality is not working

I am completely new to Ruby On Rails, and going through this guide to build a basic application.

When I am trying to implement the delete functionality as mentioned in the document, I am seeing the show page.

I have below method in my controller:

def destroy
  @article = Article.find(params[:id])
  @article.destroy

  redirect_to articles_path
end

and below line in my page:

<td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %></td>

Now when I click on the link, I am seeing below URL in browser:

http://localhost:3000/articles/1

Now now in this case I am seeing the show screen instead of getting an alert message and then deleting the record from my page.

I have followed this SO post - Rails 4 link_to Destroy not working in Getting Started tutorial

and verified that

//= require jquery
//= require jquery_ujs

elements are there in my application.js

Please tell me where I am doing mistake?

ActiveRecord 'where' clause using function

I am trying to apply filters on an ActiveRecord::Relation. I would like to apply a 'where' clause (or the equivalent) to make the following call.

record = Record.all
record.where(record.remaing_units > 5)

I know this would be easy to get coding a fonction and passing it 2 arguments but I would like to know if there is a cleaner way to do it, more 'where' like.

Cucumber: How to implement feature directory specific support/hooks.rb functionality?

We're using Cucumber as our test harness

We have a folder structure like this:

- automation
    - api
        - api1.feature
        - api2.feature
    - gui
        - gui1.feature
        - gui2.feature
    - step_definitions
        - api_steps.rb
        - gui.steps.rb
    - support
        - hooks.rb
    - cucumber.yml
    - env.rb
    - Gemfile
    - Rakefile

I need to have different actions occurring in my hooks.rb file (or support directory in general) for the api tests vs. the gui tests. For my api tests, I need to authorize through our restapi and get an auth cookie. For my gui tests, I need create a selenium browser instance.

I need this to work both when I execute everything by issuing 'cucumber' alone from the 'automation' level of this folder structure AND when I execute a single feature file by doing:

    $ cucumber gui/gui1.feature -r features

So my questions are regarding how best to do that.

  1. Can I/should I create some kind of conditional within my hooks.rb file in the 'Before do' block to perform different before actions based on which directory the feature is executing from?
  2. OR Can I/should I create separate support/hooks.rb directories/files within each of the directories 'api' and 'gui'? (effectively will Cucumber recognize and selectively utilize multiple support directories?)

Thanks!

How to extract bike listings using information from 3taps API

Developing a Ruby on Rails app using information from the 3 taps API. The information I want is from Craigslist. Want to extract information on bikes for sale in the UK.

the following gives me the category information for bikes for sale

{
            "code": "SBIK",
            "group_code": "SSSS",
            "group_name": "For Sale",
            "name": "Bicycles"
        },

so in my browser i add the following

http://ift.tt/1JUkbYx

{
"success": true,
"anchor": 2110058535,
"postings": [
{
"id": 2109916051,
"source": "CRAIG",
"category": "SBIK",
"external_id": "5010763041",
"external_url": "http://ift.tt/1EV9Yqu",
"heading": "WTB:  Tri-bike...56-58cm",
"timestamp": 1430838700,
"annotations": {
"source_map_yahoo": "http://ift.tt/1JUka6W",
"source_continent": "USA",
"latlong_source": "In Posting",
"source_heading": "WTB:  Tri-bike...56-58cm",
"source_cat": "sss",
"proxy_ip": "104.236.116.193:22225",
"source_state": "North Carolina",
"phone": "5010763041",
"source_account": "5hz2n-5010763041@sale.craigslist.org",
"gzip_data_size": "4170",
"source_loc": "wilmington",
"source_subcat": "bia|bik",
"html_data_size": "12631",
"source_map_google": "http://ift.tt/1EV9Yqw"
},

but when i add the country code -which is GBR i get nothing i have added http://ift.tt/1JUkbYz

but get error {"success":false,"error":"level params not supported in polling"}

when i do a location search it works using the metro field

http://ift.tt/1EV9Yqy

"locations": [
{
"bounds_max_lat": 57.21864,
"bounds_max_long": -2.06182,
"bounds_min_lat": 57.10158,
"bounds_min_long": -2.22161,
"code": "GBR-ABD",
"full_name": "Aberdeen, United Kingdom",
"short_name": "Aberdeen"
},
{
"bounds_max_lat": null,
"bounds_max_long": null,
"bounds_min_lat": null,
"bounds_min_long": null,
"code": "GBR-BAT",
"full_name": "Bath, United Kingdom",
"short_name": "Bath"
},

but when i add this to my polling search , i cannot get this to return any values for bikes for sale in the uk?

http://ift.tt/1JUka6Y

also used &location.city=GBR-MAN to find bikes in manchester which returns error

i get {"success":false,"error":"level, country params not supported in polling"}.

ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`

I am trying to implement a "comment" feature as part of my assignment for an project I am building.

Earlier in the course we created a comment table and had the Faker gem generate fake comments.

My instructions are as follows:

Comments must be associated with users, so add a user_id foreign key to the comments table. Remember to add an index to it too;

Update the User model so you can call user.comments, and the Comment model so you can call comment.user;

Modify the seeds.rb file to create valid comments when you run db:reset;

Initially I tried to run my rails generate commands but kept running into this error:

▶ rake db:migrate
== 20150508143445 CreateComments: migrating ===================================
-- create_table(:comments)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
SQLite3::SQLException: table "comments" already exists
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

So I discovered that I needed to delete the old table from the start of the course. I did this in the console.

ActiveRecord::Base.connection.execute("drop table comments")

It seemed to work. I was then able to run these in terminal.

▶ rake db:migrate
== 20150508143445 CreateComments: migrating   ===================================
-- create_table(:comments)
   -> 0.0015s
== 20150508143445 CreateComments: migrated (0.0016s) ==========================

== 20150508152354 DropComments: migrating =====================================
== 20150508152354 DropComments: migrated (0.0000s) ============================

▶ rails g migration AddCommentToUsers commed_id:integer:index
  invoke  active_record
  create    db/migrate/20150508155200_add_comment_to_users.rb

▶ rake db:migrate
== 20150508155200 AddCommentToUsers: migrating ================================
-- add_column(:users, :commed_id, :integer)
   -> 0.0010s
-- add_index(:users, :commed_id)
   -> 0.0012s
== 20150508155200 AddCommentToUsers: migrated (0.0023s) =======================

models/comment.rb

class Comment < ActiveRecord::Base
  belongs_to :user
end

models/user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable
  has_many :posts
  has_many :comments

  # CarrierWave method for attribute functionality
  mount_uploader :avatar, AvatarUploader

  # These methods check the role of a user in the database
  def admin?
    role == 'admin'
  end

  def moderator?
    role == 'moderator'
  end
end

migrations/create_comments.rb

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.text :description

      t.timestamps null: false
    end
  end
end

migrations/add_comment_to_users.rb

class AddCommentToUsers < ActiveRecord::Migration
  def change
    add_column :users, :commed_id, :integer
    add_index :users, :commed_id
  end
end

In my seeds.rb I have changed

# Create Comments
50.times do 
  Comment.create!(
      # user: users.sample, # we have not yet associated Users with Comments
    post: posts.sample,
    description: Faker::Lorem.paragraph
    )
end

to

# Create Comments
50.times do 
  Comment.create!(
    user: users.sample,
    description: Faker::Lorem.paragraph
    )
end

Now when I run rake db:reset I get this error.

▶ rake db:reset
-- create_table("advertisements", {:force=>:cascade})
   -> 0.0047s
-- create_table("answers", {:force=>:cascade})
   -> 0.0010s
-- add_index("answers", ["question_id"], {:name=>"index_answers_on_question_id"})
   -> 0.0014s
-- create_table("comments", {:force=>:cascade})
   -> 0.0010s
-- create_table("posts", {:force=>:cascade})
   -> 0.0010s
-- add_index("posts", ["topic_id"], {:name=>"index_posts_on_topic_id"})
   -> 0.0010s
-- add_index("posts", ["user_id"], {:name=>"index_posts_on_user_id"})
   -> 0.0014s
-- create_table("questions", {:force=>:cascade})
   -> 0.0010s
-- create_table("summaries", {:force=>:cascade})
   -> 0.0010s
-- add_index("summaries", ["post_id"], {:name=>"index_summaries_on_post_id"})
   -> 0.0010s
-- create_table("topics", {:force=>:cascade})
   -> 0.0036s
-- create_table("users", {:force=>:cascade})
   -> 0.0015s
-- add_index("users", ["commed_id"], {:name=>"index_users_on_commed_id"})
   -> 0.0009s
-- add_index("users", ["comment_id"], {:name=>"index_users_on_comment_id"})
   -> 0.0012s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
   -> 0.0015s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
   -> 0.0017s
-- initialize_schema_migrations_table()
   -> 0.0034s
rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)

Here is the full stack trace:

ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute.rb:138:in `with_value_from_database'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_set.rb:39:in `write_from_user'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods.rb:373:in `[]='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/singular_association.rb:17:in `writer'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:123:in `user='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `public_send'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:559:in `init_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:281:in `initialize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/persistence.rb:50:in `create!'
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:547:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/jon/code/Bloccit/bin/rake:8:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed

I am stumped here. I thought by deleting the old table and running the new generate commands + migrating everything would be in order. Apparently this is not the case.

What am I doing wrong here?

edited to include line 45 of my seeds.rb

Comment.create!(

Get path to capistrano shared path from ruby

I know that I can get the location of my rails app with Rails.root:

> Rails.root
 => #<Pathname:/var/www/app-name/releases/20150507181426>

I am looking for the function to call to get capistrano's shared folder, which in this case is found here:

/var/www/app-name/shared/

I need to be able to get the path from within ruby code. Thanks in advance.

This is error redmine when it load web redmine

Anyone can help me :(

This is error my redmine when i load web redmine

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

vi /etc/httpd/logs/error-log:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/http.so' - /usr/lib64/php/modules/http.so: undefined symbol: php_persistent_handle_abandon in Unknown on line 0
[Fri May 08 22:53:08 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.9 Phusion_Passenger/5.0.7 mod_ruby/1.3.0 Ruby/1.8.7(2013-06-27) mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
App 16448 stderr: Cannot execute "/usr/local/rvm/gems/ruby-2.1.5/gems/passenger-5.0.7/buildout/support-binaries/PassengerAgent": Permission denied (errno=13)
[ 2015-05-08 22:53:45.6201 16404/7f9d4c49e700 App/Implementation.cpp:287 ]: Could not spawn process for application /storage/www/redmine.vieter.vn: An error occured while starting up the preloader.
  Error ID: ae4aaf6b
  Error details saved to: /tmp/passenger-error-oXXkpt.html
  Message from application: Cannot execute "/usr/local/rvm/gems/ruby-2.1.5/gems/passenger-5.0.7/buildout/support-binaries/PassengerAgent": Permission denied (errno=13)


[ 2015-05-08 22:53:45.6293 16404/7f9d4cee0700 age/Hel/Req/CheckoutSession.cpp:252 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is ae4aaf6b. Please see earlier logs for details about the error.

ruby 2.1.5 / gem 2.4.3 / passenger 5.0.7

vi /etc/httpd/passenger.conf

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.5/gems/passenger-5.0.7/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
    PassengerRoot /usr/local/rvm/gems/ruby-2.1.5/gems/passenger-5.0.7
    PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.5/wrappers/ruby
</IfModule>

Ruby Error: koala no such file to load LoadError

I have installed Ruby (not Rails) on a machine and am trying to run some code based off the koala framework for Facebook.
When I run

    gem list

koala is mentioned but when I run the file, I get this error. Rubygems is already installed, I'm not sure what else to do. Any ideas?

Edit:

    require 'koala'
    require 'json'

    @graph = Koala::Facebook::API.new("CAACEdEose0cBANb7YuygrBflSkBrpdalb4e70T5lJgdLPYEh0Uxy5JLPVdukKSiwZAK8g27DnwscSUWNaC0s53ogq6h562LETjYO4sB5lZAMAy8tC0SM9UzqXkk7GKYpaLrkQlgj1oLTdOJhBfq5KJtFxZBkOkpz8HaVPLYp66OnuGkaGOogVseR1tUNXVxToKl6ZCmwHL0i5RHNvMnd")




    url = File.open("urls.txt","r")
    url.each_line do |line|
        id = /[\d]+/.match(line)
        begin
            temp = @graph.get_object(id)
            list = File.open("working.txt", "a")
            list.write(id)
            list.write("\n")
            puts "Worked for #{id}."
        rescue
            puts "Didn't work for #{id}."
        end      
    end 

puts "nil" if it is not in range

def binary_search(num, test_array)
  counter = 0
  low = 0
  high = test_array.length

  while (low <= high) do
    i = ((low + high) / 2).floor;
    if num == test_array[i]
      return i
      break
    elsif num < test_array[i]
      high = i
    elsif num > test_array[i]
      low = i
    end
    counter += 1
  end
end

test_array = [13, 19, 24, 29, 32, 37, 43]
# binary_search(35, test array)?
# binary_search(11, test array)?

in this code, how can I make sure it will return "nil" if it is binary_search(35), or binary_search(11)?

RSpec "retest broken tests from last time" flag

Is there any way to retest previously broken tests?

So, say, I run rspec and several tests in different files and directories fail. I fix something and now I have to manually specify all files and folders I want to retest or run tests for whole project again(It takes considerable amount of time for big projets).

What I was looking for is something like a flag

rspec --prev-failed-only

I realize that such flag would require considerable amount of additional actions from rspec, like storing results of previous tests and so on. But I think it would be super convenient to me.

Is there any such(or similar) tool/gem?

How to add extra param on best_in_place field update in ruby

I am using best_in_place gem for In-line edit for a field in active admin. Please look at my code below,

column "Badge ID", :number do |event|
   best_in_place event, :number, :type => :input, :path => [:admin, event]
end

This is what the parameters sent to the controller action.

Parameters: {"event"=>{"number"=>"499"}, "authenticity_token"=>"xxxxxxxx", "id"=>"995"}

Now, I want to send additional parameter along with the number either inside or outside the event hash.

Anyone, Please help me resolve this.

How do I include a ruby gem's code into main rails project?

Let's say that I need to change the functionality of a certain ruby gem that I need in my rails project. I would like to place all the content of the ruby gem inside the main project.

Is this possible? Are there alternative methods?

Thank you

How do I ignore the nil values in the ruby loop with parsed values from Mechanize?

In my text file are a list of URLs and with Mechanize I'm using that list to parse out the title and meta description. However, some of those URL pages don't have a meta description which stops my script with a nil error.

undefined method `[]' for nil:NilClass (NoMethodError)

I've read up and seen solutions if I were using rails, but for ruby I've only seen .reject and .compact as possible solutions to ignore nil values. I added .compact at the end of the loop, but that doesn't seem to do anything.

require 'rubygems'
require 'mechanize'

File.readlines('parsethis.txt').each do |line|
    page = Mechanize.new.get(line)
    title = page.title
    metadesc = page.at("head meta[name='description']")[:content]
    puts "%s, %s, %s" % [line.chomp, title, metadesc] 
end.compact!

how to get result from executing a set of system commands in a Ruby script

I am running a set of system commands in my Ruby script , and I would like to get the result (true /false) of the execution ( as I already did for a single command

  unless system("mkdir -p #{project_path}")
     puts "Cannot create local project directory." 
     exit 1
 end

for a set of commands I tried :

unless system <<EOC
  cp "#{dockerfile_template}" "#{project_path}"
  cd "#{project_path}"
  git init .
  git add -A
  git commit -m "first commit" 
  git remote add origin "#{project_repository}"
  git push -u origin master
EOC
exit 1
end

but it's failing : => an't find string "EOC" anywhere before EOF any suggestion welcome ...

Pass class object from ruby to liquid (via Jekyll)

UPDATE FOR CLARIFICATION.

I deleted the original question because it was confusing. Maybe this one is better?

I currently have something like this (simplified for brevity):

module Jekyll
    module TOCGenerator
        def toc(html)
            ...via nokogiri, get all <h3> tags, make table of contents entry
            for each. 
        end
        def contentWithTocAnchorLinks(html)
            ...make "back to top" anchor links under each <h3> tag that will
            take the user back up to the table of contents 
        end
    end
end

Then in the template:

<section>{{ content | toc }}</section>
<section>{{ content | contentWithTocAnchorLinks }} </section>

This works fine, but it seems sloppy. I've also tried stuffing both toc and contentWithAnchorLinks into an array and then doing something like {{ content | tocArray | first }} which also worked, but not very well (in some cases there is no table of contents and it was confusing). Anyway, what I would like to be able to do is something like this:

{% capture toc_content %}{{ content | toc_generate }}{% endcapture %}
<section> {{ toc_content.toc }} </section>
<section> {{ toc_content.content }}</section>

Jekyll does this all the time, as in {{ page.title }} but I'm not clear on how to replicate it. I only assume that a Ruby class is involved somewhere.

Does that make more sense?

Ruby on Rails - FTP error attempting to download file

I am using the following code to download a handful of .csv files from my FTP server:

require 'net/ftp'
ftp = Net::FTP.new
ftp.connect('myftpserver.com', '21')
ftp.login('mylogin', 'mypassword')
ftp.passive = true

  files = ftp.list

  puts files

  ftp.gettextfile('cutandsold-us.csv', './lib/cutandsold-us.csv')
  puts "#{Time.now} > Downloaded Cut and Sold report (US)."

  ftp.gettextfile('cutandsold-canada.csv', './lib/cutandsold-canada.csv')
  puts "#{Time.now} > Downloaded Cut and Sold report (CAN)."

  ftp.gettextfile('stylemaster.csv', './lib/stylemaster.csv')
  puts "#{Time.now} > Downloaded Style Master."

  ftp.gettextfile('acct-bookings-large.csv', './lib/acct-bookings-large.csv')
  puts "#{Time.now} > Downloaded Account Bookings report."

  ftp.gettextfile('acctbookings-majors.csv', './lib/acctbookings-majors.csv')
  puts "#{Time.now} > Downloaded Major Account Bookings report."

  ftp.gettextfile('customerlist.csv', './lib/customerlist.csv')
  puts "#{Time.now} > Downloaded Customer list."

ftp.close

All of the files download fine except for "customerlist.csv", despite this file being on the FTP server (I can download using FileZilla), and it shows up with the correct filename in the console when "puts files" occurs.

When the line to download "customerlist.csv" is reached, the following error is returned:

/Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:341:in `voidresp': 150 0.085 seconds (measured here), 1.11 Mbytes per second (Net::FTPReplyError)

I suspect it is an issue with the file itself and not my code as the other files download without issue, but I am not sure because the file appears to be intact and I can download it with another FTP client.

acts_as_tree default foreign key column

Rubydoc says,

By default, ActsAsTree expects a foreign key column called parent_id

My question is, how can we change the default foreign key column to some custom column?

Setting Pakyow for local development with Postgres

In the blog post about connection to postgres, http://ift.tt/1DxWvp8, how do you deal with Postgres setup and required password errors?

I've been developing in Nitrous.io but now setting up local development. So I set the DATABASE_URL as in the post but trying to run pakyow server it gives an error about: "pg::connectionbad: fe_sendauth: no password"

The only user in Postgres is 'postgres' and it has a password associated. It wouldn't let me install without creating a password.

Also, is it bad practice to not have a Postgres password for local dev? Articles about it weren't clear (and were related to Rails) and mentioned database.yml storing the password, which Pakyow doesn't seem to have.

add info from rails_admin

i'm new in rails, and i'm building a rails app for a architect, so a client have many pictures. So i make my DB client and picture, and their link are in picture, the client_id.

https://www.youtube.com/watch?v=abcnfFS_DS8 This video help me a lot (see around 30min)

I don't want to create some forms or scaffolding system, i'd like to use the rails_admin gem to upload my picture(this is ok) and i propose to makes the relation and choose witch client i'd like to use, but this let my client_id at nil.

What should i do ?

This is my controller :

class RealisationController < ApplicationController
def real
    @clients = Client.all
    @pics = Picture.all
end

This is my models :

class Picture < ActiveRecord::Base
    belongs_to :client
    attr_accessible :client_name, :picture, :client, :image

    has_attached_file :image,
        :styles => { :medium => "300x300", :thumb => "100x100>" },
        :path => ":rails_root/public/images/:id/:filename", #a changer pour mettre :id_client
        :url  => "/images/:id/:filename"

    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

end
class Client < ActiveRecord::Base
    # validates_presence_of :client_name
    attr_accessible :client_name, :picture, :description
    has_many :pictures, dependent: :destroy
    accepts_nested_attributes_for :pictures, :allow_destroy => true
    attr_accessible :pictures_attributes
end

This are my DB creation :

        class CreatePictures < ActiveRecord::Migration
      def change
        create_table :pictures do |t|
          t.integer  :client_id
          t.timestamps null: false
        end
      end
    end

class AddAttachmentImageToPictures < ActiveRecord::Migration
  def self.up
    change_table :pictures do |t|
      t.attachment :image
    end
  end

  def self.down
    remove_attachment :pictures, :image
  end
end

class CreateClients < ActiveRecord::Migration
  def change
    create_table :clients do |t|
        t.string   :client_name
        t.string   :description
      t.timestamps null: false
    end
  end
end

I feel it ! i'm really close to my goal ! But some help could be really helpful ..

Thanks for reading me, and sorry for my grammatical mistakes, i'm french ;)

Rails has_many api interaction

I'm adding a new api interaction to a rails app. So, for this example, I have two models: a bag, and a thing. A bag can have many things. In my bag model, I have

has_many :things, :class_name => 'Api::Things'

and in my things model, I have

belongs_to :bag, :class => 'Api::Bag'

In my api (written in Go) I have

// Represents the json object that is returned to the end user when a request is made
type Thing struct {
    Id              int     `db:"id" json:"id"`
    Name            string  `db:"thing_name" json:"thing_name"`
    ThingTypeId     int     `db:"thing_type_id" json:"thing_type_id"`
}

type ThingCollection struct {
    Data []*Thing `json:"things"`
}

func (m *ThingCollection) List(bag_token string) error {
    sql :=
        `SELECT
            ifnull(t.id,0) as id,
            ifnull(t.thing_name,"") as thing_name,
            ifnull(t.thing_type_id,0) as thing_type_id
        FROM ` + dbNames.fakeDB + `.things t
        JOIN ` + dbNames.fakeDB + `.bags b ON b.id = t.bag_id
        WHERE b.token = '` + bag_token + `'`

    return mysql.DB.Select(&m.Data, sql) --the mysql is defined in an import
}

I want my things to be populated when I make the api call to return a bag. This is not happening when I make that call in the bag controller. Do I need some kind of def self in the thing model? Am I missing something else?

Surveyor: Routing Directly to a New Survey (Rails)

I'm hoping someone can enlighten a noob as to the 'Rails Way' of redirecting to a specific survey using the Surveyor gem (1.4.0pre). I've created a separate 'Members' model to capture an email address on landing, and when Submit/Next is clicked, I'd like that email address persisted to the db and the desired survey shown.

MembersController:

def create
  @member = Member.new(member_params)
  if @member.save
    flash[:success] = "Thanks for taking part!"
    # This should redirect to the new survey.....
  else
    render 'new'
  end
end

I've read the gem documentation and it states a POST request to surveys/name-of-survey/ is required, but I understand redirect_to issues a GET request and calling a method of one controller (surveys) from within another controller (members) is bad news and not advised.

Any assistance on how to implement the desired behaviour would be greatly appreciated!

Thanks.

Array cannot be coerced into Fixnum (TypeError)

I have written a basic program of calculations. The program runs fine for some input, while gives TypeError for others. I can't figure out the reason behind this unpredictable behavior. Here's my code -

class Conversion
I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000
result = 0
puts "enter the string"
input = gets.chomp.upcase
temp = input.split(//)
for i in temp do
    case i
        when 'M'
            result = result + M
        when 'D'
            result = result + D
        when 'C'
            result = result + C
        when 'L'
            result = result + L
        when 'X'
            result = result + X
        when 'V'
            result = result + V
        when 'I'
            result = result + I
        end
   end
   puts result
end

The error log is as-

assignment1.rb:22:in +': Array can't be coerced into Fixnum (TypeError) from assignment1.rb:22:inblock in ' from assignment1.rb:7:in each' from assignment1.rb:7:in' from assignment1.rb:1:in `'

Now, when I supply input like mxcd, dcm, lxv etc it works fine. But for inputs like xvi, ivx, icd it gives TypeError.

Need help with it. Thanks in advance.

Rails Backup: Generating Backup Model not running with dokku

Using Backup gem to do a DB backup, deployed the app with the gem installed to DigitalOcean and the next step is to run the generator using

dokku run oktob bundle exec backup generate:model --trigger oktob_db_backup --databases="postgresql" --storages="dropbox" --encryptors="openssl" --compressors="gzip" --notifiers="mail"

this should create the configuration files to setup the backup, but it returns nothing.

enter image description here

When I run the generator on my local machine, 2 files are generated as normal as but this time without using dokku run oktob as it's on a local machine.

Generated model file: '/Users/ahmadajmi/Backup/models/oktob_db_backup.rb'.
Generated configuration file: '/Users/ahmadajmi/Backup/config.rb'.

Thanks

Ruby Closures: How to return args and block as a single argument to pass to a method

Suppose I have a method that takes args and a block:

def yield_if_widget(*args, &block)
  if args[0].is_a?(Widget)
    block.call
  end
end

I can call this method with arguments and a block:

yield_if_widget(Widget.new) do
  puts "I like widgets"
end

But what if I have another method that prepares the arguments and the block:

def widget_and_block
  args = [Widget.new]
  block = proc{ puts "I like widgets" }

  [args, block]
end

And I want to be able to pass it directly to the first method:

yield_if_widget(*widget_and_block)

Is this possible? How? Assume that yield_if_widget is defined in a library and monkey-patching it is not an option.

Compass can't resolve relative image path

Scenario

File structure:

ui/components/gritter/gritter.scss
ui/components/gritter/images/gritter.png
ui/images/foo.jpg

Gritter.scss

.bottom
{
   background: image-url("images/gritter.png");
}

And my compass config:

images_dir = '/'
project_path = "ui/"

Problem

When I compile, compass tries to resolve the image path to /ui/images/gritter.png, which does not exist.

How can I make compass to look for images relative to tue .scss file before trying to resolve it to project_path + images_dir?

Unable to extract Model Data Using created_at in rails 2 application

@versions = Version.find_all_by_created_at(2015-05-07)
@versions = []

datatype for created_at(datetime)

Please i want extract data by passing only date to a model .

Debug integration test

When an integration test fails, even though the thing it's testing works with manual testing, it can be hard to work out what went wrong.

Here for example (fails):

test "posts a job with valid information" do
    get new_job_path
    assert_difference 'Job.count', 1 do
      post_via_redirect jobs_path, 
        job: { title:          "Great job",
               description:    "Please apply to our great job!",
               company:        "Fast company",
               contact_info:   "Email a cv to user@fastcompany.com",
               categroy_id:    "1" },
        employer: { email: "user@fastcompany.com" },
        location: { address_1: "21 Corsham Street",
                    address_2: "Islington",
                    postcode:  "N1 6DD" }
    end
    assert_template 'jobs/show'
    assert_not flash.empty?
  end

This same data entered into the website doesn't fail.

Infact, you can output the response by changing the assert_difference line to:

    assert_difference 'Job.count', 1, @response.body do

Here, I've use the "failure message" field of the test to print the body. Unfortunately, the response is looking very weird - it looks like it just refreshed the page. How can I get in and see what's wrong?

For reference, here's the controller and view being tested:

I'm using minitest.

Controller:

 def create
    @employer = Employer.find_or_create_by(employer_params)
    @location = @employer.locations.build(location_params)
    @job =      @employer.jobs.build(job_params)
    unless @location.save
      @job.errors.delete(:employer_id)
      @location.errors.delete(:lat)
      @location.errors.delete(:lng)
      render 'new' and return
    end

    @job.location = @location

    if @job.save
      flash[:success] = "Job posted successfully!"
      redirect_to @job
    else
      @job.errors.delete(:employer_id)
      @location.errors.delete(:lat)
      @location.errors.delete(:lng)
      render 'new'
    end 
  end

View:

<% provide(:title, 'Post a Job') %>

<h1>Post a Job</h1>

<div class="row">
  <div class="col-sm-4 col-sm-push-4">
    <%= form_for(@job) do |j| %>
      <%= render 'shared/error_messages' %>
      <%= j.label :category %>
      <%= j.collection_select :category_id, Category.all, :id, :name_titleize, { prompt: "Select vehicle" }, { class: 'form-control' } %>

      <%= j.label :title %>
      <%= j.text_field :title, class: 'form-control' %>

      <%= j.label :description %>
      <%= j.text_area :description, class: 'form-control' %>

      <%= j.label :contact_info %>
      <%= j.text_area :contact_info, class: 'form-control' %>

      <%= j.label :company %>
      <%= j.text_field :company, class: 'form-control' %>

      <%= fields_for @employer do |e| %>

        <%= e.label :email %>
        <%= e.email_field :email, class: 'form-control' %>

      <% end %>

      <%= fields_for :location, @location do |l| %>

        <%= l.label :address_1 %>
        <%= l.text_field :address_1, class: 'form-control' %>

        <%= l.label :address_2 %>
        <%= l.text_field :address_2, class: 'form-control' %>

        <%= l.label :postcode %>
        <%= l.text_field :postcode, class: 'form-control' %>

      <% end %>

      <%= j.submit "Post my job", class: "btn btn-primary" %>
    <% end %>
  </div>
</div>

Ruby ArgumentError when actually providing correct arguments

Ruby complains i am not providing enough arguments to my script, which is:

    #!/usr/bin/ruby
require 'mail'

def send(file,recipients_csv)
     recipients=recipients_csv.split(",")
      recipients.each do |recipient|
       Mail.defaults do
        delivery_method :smtp,{ :address => 'localhost', :port => 25,:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}
       end
        mail = Mail.new do
         from 'noreply@mydomain.com'
         to "#{recipient}"
         subject "test"
         body "test"
         add_file :filename => "a_testfile.tsv", :content => File.read(file.path)
        end
       mail.deliver!
      end
end

testfile=File.new("newfile.tsv","w")
send(testfile,"name@mydomain.com")

What i get back is:

Mailer.rb:4:in `send': wrong number of arguments (1 for 2) (ArgumentError)
    from /usr/lib64/ruby/gems/1.9.1/gems/treetop-1.4.15/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
    from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/elements/address_list.rb:26:in `initialize'
    from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/common/common_address.rb:9:in `new'

I dont get this, the arguments i provide are obviously 2

Gem Daemons and Capistrano 3

I'm using gem - daemons. And have some misunderstanding :( How i can manage daemons after deploy? I need kill all daemons before deploy(before publish the new release) and start after finished. I have one idea:

namespace :deploy do
  desc 'Kill all existing daemons'
  task :kill_daemons do
    run( "cd #{deploy_to}/current; RAILS_ENV=production ruby lib/daemons/daemon1.rb stop" )
    run( "cd #{deploy_to}/current; RAILS_ENV=production ruby lib/daemons/daemon2.rb stop" )
  end

  after :started, :kill_daemons
  after :published, :start_daemons

  task :start_daemons do
    run( "cd #{deploy_to}/current; RAILS_ENV=production ruby lib/daemons/daemon1.rb start" )
    run( "cd #{deploy_to}/current; RAILS_ENV=production ruby lib/daemons/daemon1.rb start" )
  end
end

But how i can check the daemon is stopped?

Can't run my rspec test with jRuby and Rails 4.1.4.

I have a Rails application (4.1.4) running with jRuby 1.7.15 (1.9.3p392) 2014-09-03 82b5cc3 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_67-b01.

You can see my Gemfile at: http://ift.tt/1FTGsn5.

My Gemfile.lock: http://ift.tt/1GTsvln.

As you can see I'm using rspec (2.14.1) and rspec-rails (2.14.2).

I have a user_spec.rb file something like this:

require 'spec_helper'

describe User do
  include_context "stubbed organization"
  subject { build_stubbed(:super_admin, organization: organization) }
  let(:notification_queue) { build_stubbed(:notification_queue) }

  before(:each) do
    allow(NotificationQueue).to receive(:find_each)
  end
  it "has name assigned" do
    user = build(:member, first_name: 'John', last_name: 'Smiths')
    expect(user.first_name).to eq('John')
    expect(user.last_name).to eq('Smiths')
  end

  it "has a first name" do
    subject.first_name = nil
    expect(subject).not_to be_valid
  end

  it "has a last name" do
    subject.last_name = nil
    expect(subject).not_to be_valid
  end

end

and once I run the test I get the following results:

⇒  rspec spec/models/user_spec.rb
/Users/info/.rvm/gems/jruby-1.7.15@j-platform/gems/simplecov-0.8.2/lib/simplecov.rb:31 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See http://ift.tt/1vqGeMo
3/3: ****************************************_,------,
0/3: ****************************************_|  /\_/\
0/3: ****************************************~|_( x .x)
3/3: **************************************** ""  ""

Failures:

  1) User has a first name
     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `has_key?' for nil:NilClass
     # ./app/models/client.rb:125:in `initialize_apps_data'
     # ./spec/shared/stubbed_organization.rb:3:in `client'
     # ./spec/shared/stubbed_organization.rb:15:in `(root)'

  2) User has a last name
     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `has_key?' for nil:NilClass
     # ./app/models/client.rb:125:in `initialize_apps_data'
     # ./spec/shared/stubbed_organization.rb:3:in `client'
     # ./spec/shared/stubbed_organization.rb:15:in `(root)'

  3) User has name assigned
     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `has_key?' for nil:NilClass
     # ./app/models/client.rb:125:in `initialize_apps_data'
     # ./spec/shared/stubbed_organization.rb:3:in `client'
     # ./spec/shared/stubbed_organization.rb:15:in `(root)'

Any help would be appreciated.

ActionView::Template::Error: undefined method `is_admin' for nil:NilClass

I am using ruby 2.2/Rails 4.2 and active record on Heroku. I am getting this error on my heroku production server only. Everything works fine on my dev machine. is_admin is a boolean field I added to my Devise user table, and is checked when a logged in user tries to load a page in the admin section. If they are not an admin they get kicked to the main app page. The strange thing is that its the login page that gives this error, and is_admin shouldn't be getting called unless a) the user is logged in (Im not) and b) the user tried to load an admin page (I did not).

I installed delayed_jobs based on some advice in another thread. I got that working (I think, it at least doesn't crash my dev server) but I am still getting the same undefined_method error.

May 08 06:45:25 myappname heroku/router:  at=info method=GET path="/portal/users/sign_in" host=myappname.herokuapp.com request_id=946f39d1-7f07-4d52-a436-66c14c6734bc fwd="68.196.133.101" dyno=web.1 connect=2ms service=2943ms status=500 bytes=153 
May 08 06:45:25 myappname app/web.1:  2015-05-08 13:45:24 +0000: Rack app error: #<ActionView::Template::Error: undefined method `is_admin' for nil:NilClass> 
May 08 06:45:25 myappname app/web.1:  /app/app/views/layouts/application.html.erb:71:in `_app_views_layouts_application_html_erb___400859338153902421_70022501785140' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/template.rb:145:in `block in render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/template.rb:333:in `instrument' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/template.rb:143:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/renderer/template_renderer.rb:52:in `render_template' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/renderer/template_renderer.rb:14:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/renderer/renderer.rb:42:in `render_template' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/renderer/renderer.rb:23:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/rendering.rb:100:in `_render_template' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/streaming.rb:217:in `_render_template' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/rendering.rb:83:in `render_to_body' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:32:in `render_to_body' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/renderers.rb:37:in `render_to_body' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/rendering.rb:25:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:16:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/core_ext/benchmark.rb:12:in `block in ms' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/core_ext/benchmark.rb:12:in `ms' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:41:in `block in render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:40:in `render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:10:in `default_render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/responders-2.1.0/lib/action_controller/responder.rb:236:in `default_render' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/responders-2.1.0/lib/action_controller/responder.rb:170:in `to_html' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/responders-2.1.0/lib/action_controller/responder.rb:163:in `respond' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/responders-2.1.0/lib/action_controller/responder.rb:156:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/responders-2.1.0/lib/action_controller/respond_with.rb:203:in `respond_with' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/app/controllers/devise/sessions_controller.rb:11:in `new' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:198:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:10:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:20:in `block in process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:19:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rescue.rb:29:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `block in instrument' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `instrument' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/params_wrapper.rb:250:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:137:in `process' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/rendering.rb:30:in `process' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal.rb:195:in `dispatch' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal.rb:236:in `block in action' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:73:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:73:in `dispatch' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:42:in `serve' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/mapper.rb:49:in `serve' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:43:in `block in serve' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:30:in `each' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:30:in `serve' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:802:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/etag.rb:24:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/conditionalget.rb:25:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/head.rb:13:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/flash.rb:260:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/session/abstract/id.rb:225:in `context' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/session/abstract/id.rb:220:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/cookies.rb:560:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/query_cache.rb:36:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `_run_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_call_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/remote_ip.rb:78:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:38:in `call_app' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in `block in call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:68:in `block in tagged' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:26:in `tagged' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:68:in `tagged' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/request_id.rb:21:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/methodoverride.rb:22:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/runtime.rb:18:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/lock.rb:17:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/static.rb:113:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.1/lib/rack/sendfile.rb:113:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:518:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:164:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/configuration.rb:51:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/server.rb:507:in `handle_request' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/server.rb:375:in `process_client' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/server.rb:262:in `block in run' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/thread_pool.rb:104:in `call' 
May 08 06:45:25 myappname app/web.1:  /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.2/lib/puma/thread_pool.rb:104:in `block in spawn_thread' 

Add delimiter for best_in_place gem for rails 4

i would like to add a pipe delimter for saving a field, iam gonna add strings seperated by commas, while saving to db, replace all commas with pipe, mongodb is used for backend, anyideas?

Is there a way to upload to S3 using ruby net::ssh

I want to remotely upload a file that is on some hosts using Net::SSH

The file is really big, so I don't want to download because it takes too much time, those hosts are EC2 machines on AWS

Can Paperclip convert jpg/png images to webp format? If yes, how to use it while defining the style hash for paperclip?

I am using paperclip compression in my model and i want to convert the image into webp before uploading it to s3. But the conversion is not happening, I am still getting the png image when I am visiting the url of the image.

  class ImageTesting
  include Mongoid::Document
  include Mongoid::Timestamps
  include Paperclip::Glue

   has_attached_file :image, :processors => [:thumbnail, :compression],
  :styles => {
                :xxlarge_square => ["640x640>",  { lossless: true } , :webp],
                :xlarge_square => ["480x480>",  { lossless: true } , :webp],
                :large_square => ["240x240>",  { lossless: true } ,:webp]
              },
   :convert_options => {
      :all => '-quality 80'
    },

   :storage => :s3,
   :s3_credentials => 'xxx',
   :s3_host_name => 'xxx',
   :s3_host_alias => 'xxx',
   :url => ':s3_alias_url',
   :path => ":class/:attachment/:id/:style"

  field :image_file_name, type: String
  field :image_updated_at, type: DateTime
  field :image_content_type, type: String
  field :image_file_size, type: Integer
end

ExecJS::ProgramError in Welcome#index TypeError: Object doesn't support this property or method

I am complete new to Ruby on Rails, with great difficulty I have installed the software on my Windows 8 machine. Now I am just following this guide to create a sample Hello World example.

When I am trying to follow the steps given given in section 4.3 Setting the Application Home Page, I started facing issue.

Here is what I did:

1) Open the file config/routes.rb in your editor.

2) Uncommented the line root 'welcome#index'

3) restarted the server.

Now when I access the URL as localhost:3000 then I started getting below error on my browser:

ExecJS::ProgramError in Welcome#index 

 Showing E:/Rails/blog/app/views/layouts/application.html.erb where line #6 raised:

TypeError: Object doesn't support this property or method
  (in C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)

Extracted source (around line #6):
<head>
<title>Blog</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

Rails.root: E:/Rails/blog

Can you please tell me why I am getting this issue?

Also is developing applications using Ruby On Rails is very? because it has been 2 days since I am trying but till now I faced so many issues before I see the Hello World example. I have worked on Java based frameworks but I never faced so much difficulty in installation or creating basic applications.

LoadError: cannot load such file -- rspec/core/rake_task

When I rake, I got this error.

AllenLins-MacBook-Pro:geoblacklight allenlin$ rake -t
Resolving dependencies...
You must `gem install bundler` and `bundle install` to run rake tasks
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `require'
/Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `<top (required)>'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `load'
/Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `<main>'

However, I've run the 'gem install bundler' and 'bundle install' the rspec/core/rake_task actually exists, shown by

AllenLins-MacBook-Pro:geoblacklight allenlin$ gem which rspec/core/rake_task
/Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/rake_task.rb

I am lost here. Thanks so much for any help on this! I attached the Gemfile:

source 'https://rubygems.org'

# Specify your gem's dependencies in geoblacklight.gemspec
gemspec

# If we don't specify 2.11.0 we'll end up with sprockets 2.12.0 in the main
# Gemfile.lock but since sass-rails gets generated (rails new) into the test app
# it'll want sprockets 2.11.0 and we'll have a conflict
gem 'sprockets', '2.11.0'

# If we don't specify 3.2.15 we'll end up with sass 3.3.2 in the main
# Gemfile.lock but since sass-rails gets generated (rails new) into the test app
# it'll want sass 3.2.0 and we'll have a conflict
gem 'sass', '~> 3.2.0'
gem 'bootstrap-sass', ">= 3.2"

group :test do
  # Peg simplecov to < 0.8 until this is resolved:
  # http://ift.tt/1ImdzSt
  gem 'simplecov', '~> 0.7.1', require: false
  gem 'coveralls', require: false
end

How do I add a dependency to a private gem in gemspec?

I'm trying to add a private gem dependency to a gemspec I'm writing. My Gemfile is:

source 'https://rubygems.org'

gemspec

gem 'my_private_gem', '0.0.1', :git => 'http://ift.tt/1ImdAWA'

And the relevant line in mygem.gemspec is:

spec.add_dependency 'my_private_gem', '0.0.1'

Now I thought this would work but after running gem build mygem and gem install ./mygem.gem I get: ERROR: Could not find a valid gem 'mygem' (= 0.0.1) in any repository.

What am I doing wrong?