Affichage des articles dont le libellé est Active questions tagged ruby - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Active questions tagged ruby - Stack Overflow. Afficher tous les articles

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>