ruby-on-rails

Testing ApplicationHelper methods that rely on the current controller path

I have an method in ApplicationHelper def javascript_auto_link_tags js_path = "#{RAILS_ROOT}/public/javascripts" js = "#{controller.controller_path}.js" javascript_include_tag(js) if FileTest.exist?("#{js_path}/#{js}") end This should find a javascript file based on the current controller file name and path so controllers/admin/...

Git merge from a specific folder only.

OK, here's my problem, let me try to make it all make sense... I've created a rails website for client X. I now have a client, Y, who wants a website that does the exact same thing as client X, but with a different skin. Rails was perfect for this since all the skinning was in it's own folder and set apart from all the business logic. ...

file upload without activerecord

How do you handle file upload in rail without attaching them to active record ? I just want to write the files to the disk. Thanks, ...

Variable Passing in Rails Controller Tests

I am doing some controller testing with RSpec and Mocha. Here is an example describe MenuItemsController, "creating a new menu item" do integrate_views fixtures :menu_items it "should redirect to index with a notice on successful save" do MenuItem.any_instance.stubs(:valid?).returns(true) post 'create' assigns[:menu_i...

Test if a function is called in a Ruby on Rails unit test

I am using TestUnit and would like to determine if a function is called. I have a method in a class called Person which I set to be called 'before_update': def geocode_if_location_info_changed if location_info_changed? spawn do res = geocode end end end Then I have a unit test: def test_geocode_if_locat...

Ruby - Ajax: update session value when clicking on a link

I have this ruby function in a controller def updateSession value case value when 1,2 session[:value]=1 when 3,4 session[:value]=2 end end And I have different links that redirect to different pages. I would like to change the session value when clicking on those links by calling the updateSession function Is it...

mysql gem looking for an earlier version of libmysqlclient.16.dylib

I just upgraded to Mac OSX Snow Leopard, and recompiled mysql (5.1.39) with the Snow Leopard XCode. I also reinstalled the latest mysql gem. Now, when running rake db:migrate in a rails app, I get dyld: NSLinkModule() error dyld: Library not loaded: /usr/local/mysql/lib/libmysqlclient.15.dylib Referenced from: /usr/local/lib/ruby/...

Rails ajax methods.

I have a method I want to call using AJAX in rails but I have no idea how to do so. The method is private and has no view. Right now all it SHOULD do is replace a div tags html to show a flash[:notice]. ...

Ruby on Rails: setting future "publishing" dates for blog postings

Hello, I'm trying to set blog postings to publish at certain dates in the future. I have in my Posting model: named_scope :published, :conditions => ["publish_at <= ?", Time.now] I'm using this in my controller to call the published postings: @postings = Posting.published The development server works fine, but I believe the pro...

Question regarding RJS and usage of link_to_remote

I was working on my website when I cam across this problem, I have 100 posts in my blog and I am paginating them 10 at a time, I display the 1st 15 and display a link at the bottom which basically is implemented using the link_to_remote tag. <%= link_to_remote "More Posts", :url => {:action => 'view' ,:id => link.to_i + 1} , :html => {:...

Rails keep if false, render if true.

I have a div tag that I want to change only if a function returns true, otherwise I want it to keep the same content. I used render: nothing => true but that removes everything. <%= javascript_include_tag :defaults %> <div id="x">Hi</div> <% form_remote_tag :url => {:action => 'get'}, :update => 'x' do %> <%= text_field_tag 'url' %...

Java: HTTP Post to create new “Ride” in a Ruby on Rails application

My question is very similar to http://stackoverflow.com/questions/695971/java-http-post-to-create-new-product-in-a-ruby-on-rails-application I have a form that I want to "post" to a form that looks like this Offer:<br /> <input id="ride_togive" name="ride[togive]" size="30" type="text" /> </p> <p> Request for Offer:<br /> <input i...

DelayedJob with acts_as_ferret in production mode

I get the following error when I run my task via DelayedJob: closed stream /usr/lib/ruby/1.8/drb/drb.rb:961:in `select' /usr/lib/ruby/1.8/drb/drb.rb:961:in `alive?' /usr/lib/ruby/1.8/drb/drb.rb:1211:in `alive?' /usr/lib/ruby/1.8/drb/drb.rb:1168:in `open' /usr/lib/ruby/1.8/drb/drb.rb:1166:in `each' /usr/lib/ruby/1.8/drb/drb.rb:1166:in `o...

Clean install of Ubuntu Karmic, Ruby 1.8.7 (2009-04-08 patchlevel 160), jkraemer-acts_as_ferret (0.4.4), Rails 2.3.4 -- Errors with AAF

I have a fresh install of Ubuntu Karmic, Ruby and Rails. I checkout out a working (production) application. Created the databases and ran the rake tasks. Made sure I had all the required gems of which acts_as_ferret by Jens Krämer was one of them. Everything appears to be installed correctly. The gems are listed in environment.rb inclu...

How can I use more than one set of fixtures per table in Rails?

I want to define alternative sets of fixtures per database table. For example, class BusinessSpec describe "some aspect of businesses" do fixtures :fixture_set_1 ... end describe "some unrelated aspect of businesses" do fixtures :fixture_set_2 ... end end Is this, or something similar, possible? ...

ActiveRecord.find(array_of_ids), preserving order

When you do Something.find(array_of_ids) in Rails, the order of the resulting array does not depend on the order of array_of_ids. Is there any way to do the find and preserve the order? ATM I manually sort the records based on order of IDs, but that is kind of lame. UPD: if it's possible to specify the order using the :order param an...

What is your favorite Rails admin tool and why?

What is your favorite Rails admin tool and why? By admin tool I'm referring to those that let some users add records for all the tables, like the tool shipped with Django. This question is subjective and I believe the matter is subjective, but I think it would still be nice to be able to read other people opinions and gather data on the...

Rails send_file no-cache

What is the proper way to prevent client-side caching of a file when using send_file in rails? ...

Real time with Rails

Hi, I'm looking for a good way to implement real time feed for my users on a Rails app (Phusion passenger server). Each feed can be different depending on the user and I expect to have one new item every 20 - 60s. Periodic ajax request doesn't look like the best way to do it for me. I heard about Comet and I thought about having someth...

Can't work with more recent gems

Hi all, I'm working on a university project and my teacher set up the server for it, but after installing Ruby 1.9.x we had to return to Ruby 1.8.x, because of the Ruby 1.9/Rails 2.3.4 problem. Now, every time I build a Rails app, it's always using Rails 2.2.3 gems. I've changed the environment.rb (RAILS_GEM_VERSION = '2.3.4' ...), bu...