Given the following scenario, using activerecord:
User belongs_to Event
I want to find all the Users who do not have an Event with the name "party".
So I tried the following:
User.all(:joins => :event, :conditions => ["events.name != ?", "party"])
However, that will only return those Users who do have an event, but just not a "part...
I'm developing a system (with Rails 2.3.2, Ruby 1.8.7-p72) that has a sizable reporting component. In order to improve performance, I've created a Report model to archive old reports. The idea is that if a matching report already exists for an arbitrary set of conditions then use it, otherwise generate the report and save the results.
...
I tried creating a model called "class" (as in a graduating class of students), and encountered all kinds of problems. What are some other words or class names to avoid in Rails?
Some links I've found:
http://juicebar.wordpress.com/2007/05/30/reserved-words-in-rails/
http://railsforum.com/viewtopic.php?id=22242
...
I inherited a Rails 2.2.2 app that stores user-uploaded images on Amazon S3. The attachment_fu-based Photo model offers a rotate method that uses open-uri to retrieve the image from S3 and MiniMagick to perform the rotation.
The rotate method contains this line to retrieve the image for use with MiniMagick:
temp_image = MiniMagick::Im...
I have a string "Search result:16143 Results found", and I need to retrieve 16143 out of it.
I am coding in ruby and I know this would be clean to get it using RegEx (as oppose to splitting string based on delimiters)
How would I retrieve the number from this string in ruby?
...
I apologize for the Flame War question but frankly I don't care about that. I know these are both good languages but I would genuinely like to hear everyone's opinion on what the better is for a beginning web developer who wants to learn to build great sites and web applications. Thanks for your help.
...
Is there a Ruby/Rails function that will strip a string of a certain user-defined character? For example if I wanted to strip my string of quotation marks "... text... "
http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Chars.html#M000942
...
I need to run a ruby-script as a service. The script needs access to the ActiveRecords of a rails-app.
What would be the best way? A rake task? How can it be started as a service on both windows and linux?
...
I'm having a consistency problem using link_to_remote in rails.
I have 2 use cases of link_to_remote, and they generate different ajax. I can't figure out why, and it is driving me crazy.
Here is use case one...
<%= link_to_remote "section-", :update => "sections", :url => {:action => :destroy, :controller => "sections", :id => @sect...
I was wondering what's the point of using Ruby (or even Python) in Cocoa application development other that not learning Objective-C (which is pretty simple language and will not take to more than few days to learn). I'm new to this and I'm interested why people do this? What are Pros and Cons.
...
Recently I started using a gem called blackbook. The gem has a few issues that I would like to fix. I cloned the git repo and installed the gem locally, hoping I could mess with the source code. When I edit the source code nothing happens, so now I am thinking that I must rebuild the gem every time I make a change.
My question is thi...
With a list in Python I can return a part of it using the following code:
foo = [1,2,3,4,5,6]
bar = [10,20,30,40,50,60]
half = len(foo) / 2
foobar = foo[:half] + bar[half:]
Since Ruby does everything in arrays I wonder if there is something similar to that.
...
I am wanting to learn mac development with ruby but I'm not sure which one to go at. RubyCocoa has been around longer but I think MacRuby will beat it out in the long run..
Any suggestions??
...
I have an .erb file with form template that uses form_for helper to generate form, and some of their fields generated with text_field method. In resulting HTML I see size properties are added to every input generated with aforementioned method.
I want to control input sizes with CSS and that size property prevents me from doing it. Is t...
I have a method like this:
def foo(fruit='apple', cut="sliced", topping="ice cream")
# some logic here
end
How can I call it where I only override the topping parameter but use the default values for the others, something like this
foo('','','hot fudge')
Of course this does not work as intended, but I want to only provide a value...
I am still new to Ruby and basically just writing my first micro-program after finishing Cooper's book. I was pointed to the direction of avoiding monkey patching but the problem is I don't know what are the alternatives to achieve the same behavior.
Basically, I want to add a new method that is accessible by every string object. The obv...
Hey All,
So I have been pulling my hair out troubleshooting this bug I have been having, and I finally discovered what was causing it. I had always been under the impression that when I called
@my_model.save(false)
That I would be skipping my ActiveRecord validations. Turns out this is partially true. My objects are saving to the d...
In mid July 2008 Memoization was added to Rails core. A demonstration of the usage is here.
I have not been able to find any good examples on when methods should be memoized, and the performance implications of each. This blog post, for example, suggests that oftentimes, memoization should not be used at all.
For something that could p...
I'm trying to learn the life cycle of a rails application. When is application_controller.rb run? Is it just once every time it's changed, or on every request?
I want to know the same about the following file:
config/environments/*.rb (development, production, or test, depending on the current mode)
boot.rb
environment.rb
routes.rb
...
Hi,
My Rails app has to process and generate PDF XFA files and send to the user/browser.
Its working fine. But the issue is that before sending the file to the user, it creates 2 files in the rails tmp directory.
If 10 requests come to the pdf_controller, the number of the temp files in the tmp directory will double and it will eat up ...