I am using Ruby Mongo Driver.
#surname = coll2.find("name" => {"surname" => "testing"})
Shouldn't this be working? I get no results.
I have {"name" : { "surname" : "testing" }}
I think that the following would work too
coll2.find("name.surname"=>"testing").first
Your code should work perfectly.
> coll2.insert({"name" => {"surname" => "testing"})
# => BSON::ObjectId('4dcb2e53abad691f62000002')
> coll2.insert({"name" => {"surname" => "another"})
# => BSON::ObjectId('4dcb2e53abad691f62000003')
> coll2.find().count
# => 2
> coll2.find("name" => {"surname" => "testing"}).count
# => 1
> coll2.find("name" => {"surname" => "testing"}).first
# => {"_id"=>BSON::ObjectId('4dcb2e53abad691f62000002'), "name"=>{"surname"=>"testing"}}
For me, it worked only with curly brackets. Like that:
col2.find({"name.surname": "testing"})
Related
I am trying to setup VirtualX Assessment Software that I downloaded online.
Here is the link where I got it: https://virtualx.sourceforge.net/download.html
I managed to make it run where I was able to load its webpage but there are still some functions where I'm getting an error.
Here, I'm trying to approve a test account that registered to the platform:
When I hit approve, here is the error that I'm getting:
Here is the content of routes.db
Virtualx::Application.routes.draw do
get "errors/not_found"
get "subcategory/index"
get "subcategory/list"
get "subcategory/show"
post "subcategory/save"
post "subcategory/update"
get "subcategory/edit"
get "subcategory/new"
get "subcategory/destroy"
post "subcategory/destroy"
#resources :article
get "article/index"
get "article/show"
get "article/list"
get "article/comment"
post "article/comment"
get "article/new"
post "article/save"
get "article/edit"
post "article/update"
get "article/news"
get "article/destroy"
post "article/destroy"
get "article/delete"
post "article/delete"
match '/getBlogcategory' => 'article#getBlogcategory'
match '/thumbsUp' => 'article#thumbsUp'
match '/thumbsDown' => 'article#thumbsDown'
match '/delete_comment' => 'article#delete_comment'
get "blog_category/index"
get "blog_category/list"
get "blog_category/show"
post "blog_category/save"
post "blog_category/update"
get "blog_category/edit"
get "blog_category/destroy"
post "blog_category/destroy"
get "blog_category/new"
match '/subcategory' => 'blog_category#subcategory'
match '/subcategory_article' => 'blog_category#subcategory_article'
match '/blog' => 'blog_category#blog'
match '/categoryArticle' => 'blog_category#categoryArticle'
resources :users do
get :autocomplete_user_name, :on => :collection
end
resources :folders
get "folders/index"
get "folders/new"
get "folders/create"
post "folders/create"
get "assets/destroy"
post "assets/destroy"
match "browse/:folder_id" => "folders#browse", :as => "browse"
match "browse/:folder_id/new_folder" => "folders#new", :as => "new_sub_folder"
match "browse/:folder_id/new_file" => "assets#new", :as => "new_sub_file"
match "browse/:folder_id/rename" => "folders#edit", :as => "rename_folder"
match '/getName' => 'folders#getName'
match '/unshareFolder' => 'folders#unshareFolder'
resources :assets
get "assets/index"
get "assets/new"
get "assets/create"
post "assets/create"
get "assets/destroy"
post "assets/destroy"
match "assets/get/:id" => "assets#get", :as => "download"
match "assets/share" => "assets#share"
match "assets/unshare" => "assets#unshare"
match '/lock' => 'assets#lock'
match '/unlock' => 'assets#unlock'
resources :aboutus
resources :clientinfo
resources :images
#get "images/index"
#get "images/new"
match '/view_aboutus' => 'home#view_aboutus'
match '/view_clients' => 'home#view_clients'
match '/view_features' => 'home#view_features'
match '/view_modules' => 'home#view_modules'
match '/view_contactus' => 'home#view_contactus'
match '/deleteUsersubject' => 'users#deleteUsersubject'
match '/clientImage' => 'images#clientImage'
match '/createClientimage' => 'images#createClientimage'
get "/questions/question_type_listing"
post "/questions/new"
resources :questions do
member do
get "delete_option"
post "delete_option"
get "delete_match_option"
post "delete_match_option"
get "delete_matrix_row"
post "delete_matrix_row"
get "delete_matrix_column"
post "delete_matrix_column"
get "delete_hrcl_option"
post "delete_hrcl_option"
get "saveImage"
post "saveImage"
end
end
#post "questions/publish_unpublish"
#get "questions/publish_unpublish"
match '/publish_unpublish' => 'questions#publish_unpublish'
match '/unpublish' => 'questions#unpublish'
match '/share' => 'questions#share'
match '/saveImage' => 'questions#saveImage'
match '/sharewithCategory' => 'questions#sharewithCategory'
match'/checkMark' => 'questions#checkMark'
match'/viewQuestion' => 'questions#viewQuestion'
get "subjects/add_subject_category"
resources :subjects
post "subjects/cs"
resources :categories
resources :category_titles
resources :emails
post "attend_exams/confirm_exam"
get "attend_exams/confirm_exam"
post "attend_exams/reject_exam"
get "attend_exams/reject_exam"
resources :attend_exams
get "attend_exams/index"
match '/examination' => 'attend_exams#examination'
match '/instruction' => 'attend_exams#instruction'
match '/evaluation' => 'attend_exams#evaluation'
match '/evaluation' => 'attend_exams#ramdomizeQuestions'
match '/examComplete' => 'attend_exams#examComplete'
match '/calculateScore' => 'attend_exams#calculateScore'
match '/windowClose' => 'attend_exams#windowClose'
match 'welcome/examinee_dashboard' => 'welcome#examinee_dashboard'
#get "exams/attend_exam"
#post "exams/attend_exam"
resources :exams
# member do
#get "exams/index"
# end
#end
match '/scheduleExam' => 'exams#scheduleExam'
match '/selectQuestion' => 'exams#selectQuestion'
match '/assignQustions' => 'exams#assignQustions'
match '/selectExaminee' => 'exams#selectExaminee'
match '/assignExaminees' => 'exams#assignExaminees'
match '/previewExam' => 'exams#previewExam'
match '/deleteExamQuestion' => 'exams#deleteExamQuestion'
match '/deleteExamUser' => 'exams#deleteExamUser'
match '/getMark' => 'exams#getMark'
match '/assignExam' => 'exams#assignExam'
match '/groupExam' => 'exams#groupExam'
match '/updateMark' => 'exams#updateMark'
match '/examtype' => 'exams#examtype'
match '/create_examtype' => 'exams#create_examtype'
match '/listExamtypes' => 'exams#listExamtypes'
match '/editExamtype' => 'exams#editExamtype'
match '/deleteExamtype' => 'exams#deleteExamtype'
match '/updateExamtype' => 'exams#updateExamtype'
match '/getExam' => 'exams#getExam'
match '/showEvaluationtype' => 'exams#showEvaluationtype'
match '/hideEvaluationtype' => 'exams#hideEvaluationtype'
match '/evaluate' => 'exams#evaluate'
match '/getExamQuestions' => 'exams#getExamQuestions'
match '/manualEvaluation' => 'exams#manualEvaluation'
match '/finishEvaluation' => 'exams#finishEvaluation'
match '/getCategoryexams' => 'exams#getCategoryexams'
match '/assignEvaluator' => 'exams#assignEvaluator'
match '/getEvaluator' => 'exams#getEvaluator'
match '/evaluator' => 'exams#evaluator'
match '/delete_evaluator' => 'exams#delete_evaluator'
match '/completedExams' => 'attend_exams#completedExams'
match '/pendingExams' => 'attend_exams#pendingExams'
match '/updateCategory' => 'category_titles#updateCategory'
match '/deleteCategory' => 'category_titles#deleteCategory'
get "settings/index"
post "settings/update"
get "feedback/index"
match '/assign' => 'feedback#assign'
match '/unassign' => 'feedback#unassign'
match '/viewFeedback' => 'feedback#viewFeedback'
match '/submitFeedback' => 'feedback#submitFeedback'
match '/viewfeedbackResponse' => 'feedback#viewfeedbackResponse'
match '/feedbackResponse' => 'feedback#feedbackResponse'
get "reports/index"
get "results/index"
match '/usersResult' => 'results#usersResult'
match '/resultIndex' => 'results#index'
match '/viewUserResult' => 'results#viewUserResult'
match '/groupResult' => 'results#groupResult'
match '/examsResult' => 'results#examsResult'
match '/viewExamResult' => 'results#viewExamResult'
match '/departmentResult' => 'results#departmentResult'
match '/viewDepartmentResult' => 'results#viewDepartmentResult'
#get "examination/index"
# get "reports/generateDepartmentReport"
match '/userReport' => 'reports#userReport'
match '/viewuserReport' => 'reports#viewuserReport'
match '/examReport' => 'reports#examReport'
match '/viewexamReport' => 'reports#viewexamReport'
match '/generateUser' => 'reports#generateUser'
match '/userSubjectwise' => 'reports#userSubjectwise'
match '/generateExamReport' => 'reports#generateExamReport'
match '/departmentReport' => 'reports#departmentReport'
match '/viewDepartmentReport' => 'reports#viewDepartmentReport'
match '/generateDepartmentReport' => 'reports#generateDepartmentReport'
match '/viewDepartmentReportgraph' => 'reports#viewDepartmentReportgraph'
match '/highLevel' => 'reports#highLevel'
match '/reportYear' => 'reports#reportYear'
match '/overall' => 'reports#overall'
match '/specificDepartment' => 'reports#specificDepartment'
match '/departmentDetailed' => 'reports#departmentDetailed'
match '/semesterDetailed' => 'reports#semesterDetailed'
match '/pass_fail' => 'reports#pass_fail'
match '/generatePassfail' => 'reports#generatePassfail'
match '/fetchExam' => 'reports#fetchExam'
match '/listCategories' => 'categories#listCategories'
match '/delete_category' => 'categories#delete_category'
get "questions/index"
get "subjects/index"
# resources :settings
resources :temporary_examinee
#get "temporary_examinee/new"
#get "temporary_examinee/create"
#post "temporary_examinee/create"
#get "user_registration/new"
resources :user_registration
#resources :welcome
get "welcome/index"
get "welcome/admin_dashboard"
get "welcome/examiner_dashboard"
get "welcome/qsetter_dashboard"
get "welcome/examinee_dashboard"
post "welcome/confirm_registration"
get "welcome/confirm_registration"
post "welcome/reject_registration"
get "welcome/reject_registration"
get "welcome/user_management"
get "welcome/workflow"
get "passwords/new"
#get "passwords/forgot"
match 'groupUser' => 'users#groupUser'
match 'createGroup' => 'users#createGroup'
get "user_sessions/new"
get "users/new"
get "users/generate_temporary_password"
post "users/generate_temporary_password"
match 'activate_inactivate' => 'users#activate_inactivate'
match 'activate' => 'users#activate'
match 'inactivate' => 'users#inactivate'
#match 'users/tempexaminee' => 'users#new'
resources :users
get "users/show"
get "users/edit"
get "home/index"
get "user_sessions/new"
resources :user_sessions
match 'login' => "user_sessions#new", :as => :login
match 'logout' => "user_sessions#destroy", :as => :logout
#get "password_resets/new"
resources :password_resets do
member do
get 'confirmEmail'
get 'setPassword'
get 'savePassword'
post 'savePassword'
get 'verifyPassword'
end
end
get "password_resets/edit"
# post "password_resets/edit"
get 'verify/:id' => 'user_verifications#index'
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
root :to => 'home#index'
resources :home
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end
Here is the content of welcome_controller:
=begin
welcome_controller.rb
Description: Controller file for managing the Welcome page of the application
Created on: October 11, 2010
Last modified on: March 18, 2013
Copyright 2013 PIT Solutions Pvt. Ltd. All Rights Reserved.
=end
class WelcomeController < ApplicationController
filter_access_to :all
#layout "home"
layout :choose_layout
def choose_layout
if action_name == 'workflow'
return 'workflow'
else
return 'application'
end
end
def index
end
def workflow
end
def admin_dashboard
#setting = Setting.find(:first)
#pageCollect = params[:pageLength].to_i
if #pageCollect == 0
#pagelength = 10
else
#pagelength = params[:pageLength].to_i
end
if params[:char]
letter = params[:char]
#letter = params[:char]
#registered_examinees = User.where(["is_registered = ? and role_id = ? and is_temp_examinee = ? and name like '#{params[:char]}%'", 1,Examinee,0]).paginate(:page => params[:page], :per_page => #pagelength)
#unapproved_examinees = User.where(["is_registered = ? and confirmed != ? and role_id = ? and is_temp_examinee = ? and name like '#{params[:char]}%'", 1,1,Examinee,0])
else
#registered_examinees = User.where(["is_registered = ?",1]).paginate(:page => params[:page], :per_page => #pagelength)
#unapproved_examinees = User.where(["is_registered = ? and confirmed != ? and role_id = ? and is_temp_examinee = ? and name like '#{params[:char]}%'", 1,1,Examinee,0])
end
end
def examiner_dashboard
end
def qsetter_dashboard
end
def examinee_dashboard
end
def confirm_registration
#all_approved_users = params[:check_examinee]
#all_approved_users.each do|approved|
#user = User.find_by_id(approved.to_i)
#user.update_attributes(:is_approved => 1)
if (#user.is_approved == 0 and #user.confirmed == false) or (#user.is_approved == 1 and #user.confirmed == false) or (#user.is_approved == 2 and #user.confirmed == false)
UserMailer.user_registration_email_confirmation(#user,$pwd).deliver
end
end
flash[:success] = t('flash_success.email_verification')
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
def reject_registration
#rejected_users = params[:check_examinee]
#rejected_users.each do|rejected|
#user = User.find_by_id(rejected.to_i)
unless (#user.is_approved == 2 and #user.confirmed == false)
#user.update_attributes(:confirmed => false,:is_approved => 2)
UserMailer.examinee_registration_rejection(#user).deliver
end
end
flash[:success] = t('flash_success.email_rejection')
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
end
Here is the content of admin_dashboard:
<div id="flash_notice" style="display: none;"></div>
<h2><%= t('welcome.filter_examinees')%></h2>
<div class="formContainer">
<table class="formTable" style="border:0px;">
<tr>
<td style="width:auto;" class="lettersort"><%= link_to t('general.all'), :action=>"admin_dashboard"%> | <% for char in 'A'..'Z' %>
<%= link_to( "#{char}", :char=>char, :action=>"admin_dashboard")%>
<%end%></td>
</tr>
</table>
</div>
<%if #setting.examineeApprove == 1%>
<div class="updateStatus">
<%unless #registered_examinees.empty?%>
<div class="qestionhead">
<h3><%= t('welcome.reg_examinees')%></h3>
<%= render :partial=>"users/pageLinks"%>
</div>
<%end%>
<%unless #letter == nil%>
<%= hidden_field_tag "char",#letter%>
<%else%>
<%= hidden_field_tag "char"%>
<%end%>
<div id="examinee_activation">
<%= render 'activation', :collection => #registered_examinees%>
</div>
<br>
</div>
<%else%>
<%= t('user.user_notfound')%>
<%end%>
<script type="text/javascript">
$(document).ready(function() {
$(".pageNum").click(function(){
var data = {pageLength: this.id, char: $("#char").val()};
var url = "<%= url_for(welcome_admin_dashboard_path)%>
";
$.get(url, data)
$(".pageNum").live("click", function(){
var url = "
<%= url_for(welcome_admin_dashboard_path)%>
";
var target = url + "?pageLength=" + this.id + "&char=" + $("#char").val()
$.getScript(target,$("#" + this.id).serialize(),function(data){
});
//$.getScript(this.href,+"?pageLength="+this.id);
return false;
});
});
$("#examinee_activation .pagination a").live("click", function(){
var link = this.href
var lastChar = link.substr(link.length - 1);
if (lastChar == '#'){
return false;
}
else{
$.getScript(this.href);
return false;
}
});
});
</script>
Sorry for including everything. I am very new to this and I'm just trying to run something that was created by others. Any help to fix why I'm getting this error is greatly appreciated.
i've had my first Shopify store running for about a month now, using a PHP batch script to either create new products and variants, or to update as and when needed from an existing web-based product management system. All seems to have been running fine but i've just noticed that i'm getting an exception thrown when updating variants. I'm sure this has been working fine previously (been able to update a variant as needed) so I could do with a bit of help figuring out why this is failing now.
Here's an example:
ShopifyApiException Object
(
[method:protected] => PUT
[path:protected] => /admin/variants/4294967295.json
[params:protected] => Array
(
[variant] => Array
(
[price] => 8.00
[sku] => 2217
[id] => 2217
[product_id] => 21880
[inventory_management] => shopify
[inventory_policy] => deny
[inventory_quantity] => 1
[option1] => Plain \/ EX
[option2] => Strictly Rhythm
[option3] => SR12216
[weight] => 330
[weight_unit] => g
)
)
[response_headers:protected] => Array
(
[http_status_message] => Not Found
[http_status_code] => 404
[server] => nginx
[date] => Fri, 21 Aug 2015 14:27:03 GMT
[content-type] => application/json; charset=utf-8
[transfer-encoding] => chunked
[connection] => keep-alive
[vary] => Accept-Encoding
[x-sorting-hat-podid] => 3
[x-sorting-hat-shopid] => 2234339
[x-sorting-hat-podid-cached] => 1
[x-sorting-hat-shopid-cached] => 1
[status] => 404 Not Found
[x-frame-options] => DENY
[x-shopid] => 2234339
[x-shardid] => 3
[x-shopify-shop-api-call-limit] => 1/40
[http_x_shopify_shop_api_call_limit] => 1/40
[x-stats-userid] => 0
[x-stats-apiclientid] => 152673
[x-stats-apipermissionid] => 3265975
[x-xss-protection] => 1; mode=block; report=/xss-report/97471013-3a3c-4b82-a94d-868f9b7ac073?source%5Baction%5D=update&source%5Bcontroller%5D=admin%2Fproduct_variants&source%5Bsection%5D=admin
[set-cookie] => request_method=PUT; path=/
[x-request-id] => 97471013-3a3c-4b82-a94d-868f9b7ac073
)
[response:protected] => Array
(
[errors] => Not Found
)
[message:protected] => Not Found
[string:Exception:private] =>
[code:protected] => 404
[file:protected] => /var/www/MY-SERVER/httpdocs/shopify_tools/shopify.php
[line:protected] => 70
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/MY-SERVER/httpdocs/shopify_tools/batch_upload_items.php
[line] => 347
[function] => call
[class] => ShopifyClient
[type] => ->
[args] => Array
(
[0] => PUT
[1] => /admin/variants/4294967295.json
[2] => Array
(
[variant] => Array
(
[price] => 8.00
[sku] => 2217
[id] => 2217
[product_id] => 21880
[inventory_management] => shopify
[inventory_policy] => deny
[inventory_quantity] => 1
[option1] => Plain \/ EX
[option2] => Strictly Rhythm
[option3] => SR12216
[weight] => 330
[weight_unit] => g
)
)
)
)
)
[previous:Exception:private] =>
)
I've realised the problem - hopefully this may help someone else.
I was storing the Shopify Variant ID in an INT column in my database and Shopify Variant IDs have just recently passed the INT limit of 4294967295 - switching to BIGINT and reimporting all the Variant IDs solved the problem.
I need to write a standalone ruby script that is supposed to deal with database. I used code given below in rails 3
#connection = ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:database => "siteconfig_development",
:username => "root",
:password => "root123"
)
results = #connection.execute("select * from users")
results.each do |row|
puts row[0]
end
but getting error:-
`<main>': undefined method `execute' for #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00000002867548> (NoMethodError)
what i am missing here?
SOLUTION
After getting solution from denis-bu i used it following way and that worked too.
#connection = ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:database => "siteconfig_development",
:username => "root",
:password => "root123"
)
sql = "SELECT * from users"
#result = #connection.connection.execute(sql);
#result.each(:as => :hash) do |row|
puts row["email"]
end
Maybe try this:
ActiveRecord::Base.establish_connection(...)
ActiveRecord::Base.connection.execute(...)
connection = ActiveRecord::Base.connection
connection.execute("SQL query")
I'd recommend using ActiveRecord::Base.connection.exec_query instead of ActiveRecord::Base.connection.execute which returns a ActiveRecord::Result (available in rails 3.1+) which is a bit easier to work with.
Then you can access it in various the result in various ways like .rows, .each, or .to_hash
From the docs:
result = ActiveRecord::Base.connection.exec_query('SELECT id, title, body FROM posts')
result # => #<ActiveRecord::Result:0xdeadbeef>
# Get the column names of the result:
result.columns
# => ["id", "title", "body"]
# Get the record values of the result:
result.rows
# => [[1, "title_1", "body_1"],
[2, "title_2", "body_2"],
...
]
# Get an array of hashes representing the result (column => value):
result.to_hash
# => [{"id" => 1, "title" => "title_1", "body" => "body_1"},
{"id" => 2, "title" => "title_2", "body" => "body_2"},
...
]
# ActiveRecord::Result also includes Enumerable.
result.each do |row|
puts row['title'] + " " + row['body']
end
note: copied my answer from here
You could also use find_by_sql
# A simple SQL query spanning multiple tables
Post.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id"
> [#<Post:0x36bff9c #attributes={"title"=>"Ruby Meetup", "first_name"=>"Quentin"}>, ...]
How about this :
#client = TinyTds::Client.new(
:adapter => 'mysql2',
:host => 'host',
:database => 'siteconfig_development',
:username => 'username',
:password => 'password'
sql = "SELECT * FROM users"
result = #client.execute(sql)
results.each do |row|
puts row[0]
end
You need to have TinyTds gem installed, since you didn't specify it in your question I didn't use Active Record
I am using RubyMine with rails 3.2.12 and I am getting following deprecated warning in my IDE. Any Idea How can I solve this deprecated warning?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2.
I changed my answer after #keithepley comment
#Post.find(:all, :conditions => { :approved => true })
Post.where(:approved => true).all
#Post.find(:first, :conditions => { :approved => true })
Post.where(:approved => true).first
or
post = Post.first or post = Post.first!
or
post = Post.last or post = Post.last!
You can read more from this locations
deprecated statement
Post.find(:all, :conditions => { :approved => true })
better version
Post.all(:conditions => { :approved => true })
best version (1)
named_scope :approved, :conditions => { :approved => true }
Post.approved.all
best version (2)
Post.scoped(:conditions => { :approved => true }).all
Here is the Rails 3-4 way of doing it:
Post.where(approved: true) # All accepted posts
Post.find_by_approved(true) # The first accepted post
# Or Post.find_by(approved: true)
# Or Post.where(approved: true).first
Post.first
Post.last
Post.all
Use the new ActiveRecord::Relation stuff that was added in Rails 3. Find more info here: http://guides.rubyonrails.org/active_record_querying.html
Instead of #find, use #first, #last, #all, etc. on your model, and the methods that return a ActiveRecord::Relation, like #where.
#User.find(:first)
User.first
#User.find(:all, :conditions => {:foo => true})
User.where(:foo => true).all
I have Rails 3.0.3 with these gems:
delayed_job 2.1.4
delayed_paperclip 0.7.1
paperclip 2.3.16
paperclip-ffmpeg 0.7.0
(This combination is very specific. Some newer gems will not work with others.)
Here's my Video model:
class Video < Upload
has_attached_file :file, :default_style => :view, :processors => [:ffmpeg],
:url => '/system/:class/:attachment/:id/:style/:basename.:extension',
:path => ':rails_root/public/system/:class/:attachment/:id/:style' \
+ '/:basename.:extension',
:default_url => '/images/en/processing.png',
:styles => {
:mp4video => { :geometry => '520x390', :format => 'mp4',
:convert_options => { :output => { :vcodec => 'libx264',
:vpre => 'ipod640', :b => '250k', :bt => '50k',
:acodec => 'libfaac', :ab => '56k', :ac => 2 } } },
:oggvideo => { :geometry => '520x390', :format => 'ogg',
:convert_options => { :output => { :vcodec => 'libtheora',
:b => '250k', :bt => '50k', :acodec => 'libvorbis',
:ab => '56k', :ac => 2 } } },
:view => { :geometry => '520x390', :format => 'jpg', :time => 1 },
:preview => { :geometry => '160x120', :format => 'jpg', :time => 1 }
}
validates_attachment_content_type :file, :content_type => VIDEOTYPES,
:if => Proc.new { |upload| upload.file.file? }
process_in_background :file
end
When creating a new Video object with attachment, the original is saved, but no conversion will be done. Even calling Video.last.file.reprocess! won't to a thing except returning true. (Not sure what "true" means in this case as it didn't work.)
I tried hardcoding the path to ffmpeg in Paperclip::options[:command_path]. I even tried deleting the paperclip-ffmpeg.rb file and replacing it with a blank file. Really thinking I'd get an exception by doing the later, instead, I simply got "true" again.
It feels like the paperclip-ffmpeg.rb is being loaded, because it is required by config/application.rb, but nothing is called in it when trying to generate a thumbnail or convert a video.
Can anyone help me with this? Thanks in advance!
Looks like I solved this problem myself, and it was caused by something I did.
I wrote my own script to import files and the database from an older app to Rails. The files were in place, but someone I updated the database with the wrong file extensions (in this case, ".jpg" instead of ".MOV").
Paperclip will verify first to see if the original file exists before calling any processor, based on the file name stored in the database. As it didn't, Paperclip just didn't do anything. Once I had the data corrected, everything ran as expected. (I had problems with FFMPEG, but that's a different issue.)
My apologies if I wasted anyone's time. Hope this can be helpful for someone.
I use a similar configuration for one of my project (but Rails 3.1.1) and everything works fine. I added paperclip-ffmpeg to my Gemfile not with config/application.rb. Maybe this helps!?