How do I disable transactions in Rails' ActiveRecord? I have a specific situation where I want them to go away I can't seem to find anything useful out there. Is it even possible?
Does such a thing exist?
Building a Rails based web application where users can upload an audio file of them speaking that then needs to be compared to another audio file for the purposes of determining how similar to voices are. Ideally I'd like to simply get a response that gives me a score of how similar they are in terms of percentage (e.g. 75% similar etc...).
Anyone have any ideas?
Thanks
I have controller with action new, and I want it to create ActiveRecord::Base descendant object, and write it into database (without showing it to user).
def new
active_order = current_user.orders.find {|o| o.status > 0 }
active_order = Order.new if active_order.nil?
(...)
end
Order.new creates local object, but my question is -- how to make Rails to fill it with default values and write to database?
I have a file "Gemfile" in my Rails project root.
It says source :gemcutter in the very first line.
Do I still need the line? If I'm correct, http://rubygems.org/ is the official source, and Gem Cutter was merged into rubygems.org.
Is there a built-in way or a more elegant way of restricting a number num to upper/lower bounds in Ruby or in Rails?
e.g. something like:
def number_bounded (num, lower_bound, upper_bound)
return lower_bound if num < lower_bound
return upper_bound if num > upper_bound
num
end
Can anyone please tell me how to delete a recurly account. As, I have tried with the following commands,
r = Recurly::Account.find(account_code)
r.delete
And also, I have tried with "r.destroy".
But, it only changing the state of recurly account from "active" to "closed" and not deleting the account completely.
I am using rails 2.3.11 for this application.
Thanks in advance.
K. Subrahmanyam.
Do the following two lines of code behave in exactly the same way despite slightly different implementations
values.map{ |k,v| __send__('%s=' % k.to_s, v) }
values.map{ |k,v| __send__("#{k.to_s}=", v) }
The second line would be a more common ruby idiom so I was wondering why the other method was used when this was in the Rails Core which I would expect to use idiomatic ruby.
I have ruby 1.8.x on:
1 x Snow Leopard
n x CentOS (mostly are my clients)
1 x Windows XP
Once recently I installed RVM to have multiple ruby versions on my Mac. Basically none of my production Rails projects is running on on 1.9.x ruby.
So, what makes you to move to 1.9.x?
Hi,
I jus created a rails application. I created a model using ruby script/generate model Article
next i edited the my articles.rb file by adding these lines in self.up method
def self.up
create_table :articles do |t|
t.string :title
t.text :body
t.string :published_at
t.timestamps
end
end
Now i ran rake db:migrate . But migrate does not work, it simply does no print anything. Anyone knows where i am going wrong?
I am new the language and I need to know what are the top things that are absolutely necessary to know in order to make a fully functional website or web app using the Ruby programming language?
Mainly Ruby onRails with Rake and other tools that mainly use Rake.
I have a file at lib directory in my rails project. like this
a (directory)
a1
a2
a.rb
when I in a.rb require a1.
require 'a/a1'
it will warn me /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- a/a1 (MissingSourceFile)
but use dirname(FILE), it work.
require File.dirname(__FILE__) + '/a/a1
why?
I've been working on a log viewer for a Rails app and have found that I need to read around 200 lines of a log file from bottom to top instead of the default top to bottom.
Log files can get quite large, so I've already tried and ruled out the IO.readlines("log_file.log")[-200..-1] method.
Are there any other ways to go about reading a file backwards in Ruby without the need for a plugin or gem?
I can't seem to find this and I feel like it should be easy. In Ruby onRails, how do I take:
2010-06-14 19:01:00 UTC
and turn it into
June 14th, 2010
Can I not just use a helper in the view?
I am trying to test a controller method with the following code:
it "should set an approved_at date and email the campaign's client" do
@campaign = Campaign.create(valid_attributes)
post :approve, id: @campaign.id.to_s
@campaign.reload
@campaign.approved_at.should_not be(nil)
end
However, when I run this test, I get the following error:
Failure/Error: @campaign.reload
ActiveRecord::RecordNotFound:
Couldn't find Campaign without an ID
When I run the analagous lines in the rails console, the reload works and the value is set as I need it to be. Why isn't reload working for me when I run the code in an rspec test?
from title, I create Rails application and use Paperclip to manage file upload but I don't want to store file in local machine, I want to store file in other machine via ftp.
Paperclip provide to store file in S3 storage, I want to make paperclip can do like S3 but via ftp.
Help me please.
Hi there
I have a question to the following procedure:
script/generate scaffold product
title:string description:text
db:migrate
#then I generate a migration which adds a column description to the
table products and migrate the db
again.
My question is: why is the field description not added to the project-views? Is that normal rails scaffold behaviour?
I think I saw in a video tutorial that the scaffold updates as well the views, which would be very convenient.
Thanks in advance for any help!
i want to put validation in ruby onrails that my username should not contain special characters like !@#$%^*()_-+=/<?:'";.
Please tell me how can i implement it in my code.
Hi,
I'm developing a Rails application with Rspec for unit testing.
Weeks ago, Rspec used to migrate the database to the last version automatically when executing 'rake spec', but now it doesn't do it automatically, I have to implement everything for myself.
This happens in test environment, because my development data doesn't desappear.
Is my fault? I didn't change anything, I think :)
Thanks in advance.
I want alternative rows in my table to be shaded. what is the best way to do this, javascript, rails?
Today, i do a simple <% num % 2%, but this is such a common operation that i think there should be a smarter way to do it
Really simple question - how do I do a search to find all records where the name starts with a certain string in ActiveRecord. I've seen all sorts of bits all over the internet where verbatim LIKE SQL clauses are used - but from what I've heard that isn't the 'correct' way of doing it.
Is there a 'proper' Rails way?
I've been reading all kinds of tutorials on how to deploy rails apps on heroku from windows.
I've tried installing git, heroku gem, generating ssh keys and setting paths and everything...
I get either public key error (without putty) or fatal no auth found (with putty)...
I am working on Ruby onRails application, with Prototype.
I want to display a loading div automatically with every ajax request and hide it on completion, without writing code for every ajax request in my application.
Is there anyway to do this.
<div id="loader">Loading...</div>
In my ruby onrails project
in model, I have some of definition.
class PlaySport < ActiveRecord::Base
belongs_to :user
belongs_to :sport
def self.getLevel
end
def self.check_play_sport(cuser_id,sport_id)
end
def current_playing_sport
end
def all_played_sports
end
end
I catch for this relation like this
current_user.play_sports.current_playing_sport
But I get the undefined method error "current_playing_sports"
What is wrong
When generating specs with :
rails g controller Home index
A spec is generated with the older object.should syntax
require 'spec_helper'
describe HomeController do
describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end
end
Is it possible to configure the generator to use the expect syntax instead?
Desired output:
require 'spec_helper'
describe HomeController do
describe "GET 'index'" do
it "returns http success" do
get 'index'
expect(response).to be_success
end
end
end
in config/application.rb:
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :factory_girl, dir: 'spec/factories'
g.view_specs false
g.stylesheets = false
g.javascripts = false
end
Hi there.
I have a ROXML object that looks like:
class Activity
include ROXML
xml_accessor :id
end
If I have an array of these objects and call .to_xml on the array, I receive an empty xml collection:
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<activities type=\"array\">\n</activities>\n"
Any idea why or how to fix this?
I'm running Rails 2.3.5 with the newest version of ROXML.
Thanks