Suppose I do
>> a = Annotation.first
>> a.body
=> "?"
>> a.body = "hello"
=> "hello"
Now, I haven't saved a yet, so in the database its body is still ?. How can I find out what a's body was before I changed it?
I guess I could do Annotation.find(a.id).body, but I wonder if there's a cleaner way (e.g., one that doesn't do a DB query)
...
I.e., is
Post.title?
equivalent to
Post.title.present?
...
Sometimes more than one artist will be on a song. For example, Jay-z's new song "A Star is Born" features the artist Cole, and thus would be listed as "Jay-z (featuring Cole) - A Star is Born" in a catalog. My question is how to model this in my database.
Right now it's pretty simple: every song belongs_to :artist and every artist has_m...
I have a couple specific needs for my search and I'm interested to get people's opinions on what search approach makes the most sense. Based on my explanation below, would you recommend that I use basic sql queries? Or step up to a more advanced search solution, like Sphinx?
I have two models that I want to search in: products and v...
Hi everyone,
I can't start mongrel server. When I have a look at log file, it tells me that the address that I wanted to use is not available. I tried to check if there were some services using that address, but I could not find any.
The error message in log file:
`initialize_without_backlog': Cannot assign requested address - bind(2)...
Assume, I want to get a page from the web to my application and make some sort of parsing with it. How do I do that? Where should I start from? Should be some plugins/gems required? What is your usual practice in resolving such type of tasks?
...
I want a has_many relationship described below
class User < ActiveRecord::Base
has_many :mcollections, :foreign_key=>'obj_id'
end
Below is definition of table mcollections
create table mcollections (
id int not null auto_increment,
obj_id varchar(255) not null,
category ...
I have a table where I am dumping some transaction data.
I have a transaction model.
In it, there is a before_save in which I process the transaction through the credit_card gateway and use the results to fill out the rest of the fields in the transaction model.
I have a Transaction Observer watching that sends out a notification when ...
Here's my situation. I have two tables: pledges and pledge_transactions. When a user makes a pledge, he has only a row in the pledges table.
Later when it comes time to fulfill the pledge, each payment is logged in my pledge_transactions table.
I need to be able to query all open pledges which means that the sum of the amounts in the t...
I pass activerecord data from rails to JavaScript function as JSON using ajax.
my request.responseText looks like this
[{"site": {"lng": 55.1443, "lat": 25.0608}},
{"site": {"lng": 55.1065, "lat": 25.0399}}]
Below is my JavaScript code
var sites=eval('(' + request.responseText + ')');
for (var i = 0 ; i < sites.length ; i++) {
...
I.e., I want my web server to initiate a Google Search, manipulate the results, and send the result back to the user's browser.
I know there's an AJAX API designed for searching client-side with Javascript, but is there a non-AJAX API designed for server-to-server communication (like there is for maps)?
...
In rails, as the "open" method of 'rest-open-uri' package can help call restful webservice. In a project, I can use that method to call restful webservice of other projects. However, when I use "open" method to call a restful webservice of the same project, it always returns the "execution expired" error as follows. Who can tell me why, ...
Hi, I have to design a client/server system emulated on a website running Ruby on Rails that should work like this:
a page is requested by a web browser and once it's opened the server can push messages to it
I know this is not possible "naturally" but I was thinking of a sort of "java applet" that is running on that page, listening on...
Is it possible to use select fields with nested object forms feature of Rails 2.3?
Example:
Suppose you have a Article model, Category model, and a ArticleCategories join model. Article has_many Categories through ArticleCategories.
On our Edit Article form, you want to have an HTML select list of all the available categories. The u...
Hey folks,
instead of this
module ActionView
module Helpers
module FormHelper
def text_area_with_wrap(object_name, method, options)
"<span class=\"wrap\">#{text_area_without_wrap(object_name, method, options)}</span>"
end
alias_method_chain :text_area, :wrap
end
end
end
for obvious reasons I woul...
Hello,
what's the best way to download an image and save it?
My current code is:
temp_file = Tempfile.new "filename", "#{RAILS_ROOT}/tmp/"
temp_file.puts open(path_to_picture, 'User-Agent' => 'Test').read
mimetype = `file -ib #{temp_file.path}`.gsub(/\n/,"")
But it seems, that the mimetyp isn't ok.
Best regards
...
I've created three classes to represent Books, People, and BookLoans. While I am able to show the association of People to Books through BookLoans I've been seeding my database.
I now need to save a checkout of a book. It was my intention to do this action through the book controller. Specifically, creating a loan action in the BooksCon...
So I'm doing BDD with Cucumber and have a form with checkboxes populated from a database. The labels for the checkboxes contain hyperlinks. So far, not too exotic (note, this is HAML and not Erb, but it should be readable enough for any Rails person):
I would like my donation to support:
%br
- for podcast in @podcasts
= check_box_ta...
I'm really really new to rails. I haven't really written any custom validation methods and I was wondering if one exists for this or if I should write my own.
I have a boolean value for images that says whether it's featured or not. How would I validate upon creating new entries and editing that there aren't more than a given number of ...
Using the (intentionally) strange multi-line format for HAML, I'd like to have the following lines in my template:
= call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
:foo4 => 'bar4', :foo5 => 'bar5' |
-# and
= call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', |
:foo4 => 'bar4', :foo5 => 'bar5' |
...