ruby-on-rails

ruby gem flickr-fu license problem

I've trying to get the flickr-fu gem to search correctly only for commercial friendly photos but with no luck. It seems to ignore the parameter altogether. photos = flickr.photos.search(:text => "anything", :tags => 'architecture', #:license_id => '4,6,5', ...

Passing variables to Rails StateMachine gem transitions

Is it possible to send variables in the the transition? i.e. @car.crash!(:crashed_by => current_user) I have callbacks in my model but I need to send them the user who instigated the transition after_crash do |car, transition| # Log the car crashers name end I can't access current_user because I'm in the Model and not the Control...

Find similar strings in postgresql hosted on Heroku

Given an article's title, I would like to find all the similar articles in my blog based on the title only. How would you proceed? (I use postgresql and heroku) ...

Rails: Redirect within XHR

I have a Parent model which has Children. If all the Children of a certain Parent are deleted, I'd like to automatically delete the Parent as well. In a non-AJAX scenario, in the ChildrenController I would do: @parent = @child.parent @child.destroy if @parent.children.empty? redirect_to :action => :destroy, :contro...

Mysql server has gone away in rails when the database is in a faraway data center

We have two data centers located across the globe. if we run the rails app in one datacenter and point to the database located in the other data center. The app throws MySQL server has gone away like once in every 5-6 web request. and show 5000 internal server error but if we put both the app and the mysql db in the same datacenter....

[rails3] DRYing up repeating routes for several models

Hello, I have some models like News and Downloads which have_many comments :as => :commentable. Comment belongs_to :commentable and is :polymorphic. Like the comments, there are subscriptions. So my routes look like this: resources :news do resources :comments do post :like, :on => :member delete :like, :on => :member end ...

How Jammit handle view specific JavaScript

Hi guys, I'm trying to adopt Jammit in my Rails application. Default config provided in documentation grabs all js files including view specific javascript: embed_assets: on javascripts: workspace: - public/javascripts/vendor/jquery.js - public/javascripts/lib/*.js - public/javascripts/views/**/*.js - app/views/work...

Rails application structure, advice?

Hi Everyone, I am about to start working on my second ever Rails application and could do with some advice. It will probably help in my head typing this question anyway! The application's purpose is to track and monitor marketing campaigns. That makes it sound way more professional that what it actually is though. An example usage: ...

What is the difference between these two statements, and why would you choose them?

I'm a beginner at rails. And I've come to understand two different ways to return the same result. What is the difference between these two? And what situation would require you to choose one from the other? Example 1: Object.find(:all).select {|c| c.name == "Foobar" }.size Example 2: Object.count(:conditions => ['name = ?', 'Fooba...

MySQL: Query all records that have a given set of relations to another table

Yeah, kinda dumb title, but I found it hard to describe my problem. I have the following tables: properties id | name 1 | color 2 | material options id | property_id | name 1 | 1 | yellow 2 | 1 | blue 3 | 2 | wood 4 | 2 | stone substances id | name 1 | orange juice 2 | cheese rela...

Which framework is the most friendly for shared hosting environment?

I am currently comparing available web frameworks to be used for my next projects. The only criterion I need are speed and portability, i.e shared hosting friendly. I have tried Ruby on Rails, but its speed/performance is not good enough for me. I am interested in Django, but I think it is not that friendly on shared hosting - correct m...

Rails: made rake log:clear then Rails stopped logging

Hi Guys, I have cleared my Rails app's log file with rake log:clear. Then Rails stopped logging the errors.... the Logfile is still empty, even though errors appeared again. Any help? Greets, Joern. ...

rails process for saving order of awesome_nested_set using jquery & nestedsortables

Hi All, I have a categories model made with the fantastic awesome_nested set. I have successfully generated the drag and drop tree and successfully generated the complete hash of this tree using SERIALIZELIST plugin and sent it to the "array" method that I have added to my categories controller. (using jquery and nestedsortables) The ha...

How to get execution time in rails console?

I want compare time of execution Post.all and SELECT * FROM posts (or some other statements) How can i get execution time of Post.all ? ...

help with activemerchant and discount codes

any suggestions on how to use activemerchant with discount codes where cart total can = $0.00 ...

Rails Model to call Controller action

I need to call an action inside of a controller from a method inside of a model. This is something I do a lot in other language (when working with the MVC framework), however, I've never seen this done in ruby on rails. The action doesn't render anything, it simply updates a session variable. ...

How to use cache in ruby on rails

HI Everybody I wanted to use caching in my application can any one help me how to start with and which is the best tutorials for the beginners thanks in advance ...

Adding both a collection and a custom field to a Select Box

I am making a select box, and I'm using a collection in it. But at the top of all the selections I want to add something that otherwise wouldn't be in that collection. Here is my select box : = select (@organization, "tabs", @organization.tabs.collect { |t| [t.title, t.id] }, {}, {:class => "text_tab_link"} ) And I would like to ad...

Error: Thread creation failed: Cannot allocate memory

Hello, I have deployed my Rails application on server. It is working fine, but it crashed on sign_up page and server will be stop. I Checked my mongrel.log file, it give the following error. libgomp: Thread creation failed: Cannot allocate memory How can I resolved this error? Thanks. ...

Get "Response code = 500" error randomly when running cucumber

For some reason I keep getting a response code of 500 when I run cucumber, even though all the tests pass. The error occurs randomly for different tests, every time I run it. Sometimes all tests pass as well. I thought it was a memory issue, so I tried restarting my computer, but that didn't do anything. An example of the error is: ...