ruby-on-rails

How can I call an API (for example Flickr API) in Ruby on Rails? Newbie question

Im building my first app in rails and I would like to call Flickr's API I know I can use flickr-fu, rflickr or other gem but I want to do it myself from scratch to learn Say, for example, I want to call flickr.photos.comments.getList that returns the comments for a photo. The arguments are api_key and photo_id. I have both. I will get...

Ruby on Rails - One model can see module, another cannot?

Hi, I have a simple module for adding the current user to a newly created object: module AttachUsers def create_with_author(author, params) created = new(params) created.author = author created.save created end def create_with_author_and_editor(author, params) created = new(params) created.author = author...

comparing params in rails

I am doing if params[:type] = "Type A" # do something end if params[:type] = "Type B" # do something end But I think that is wrong. I should be using == However that gives me error: You have nil object when you didn't expect it What is the best way to do this in rails? All I am doing is getting a radio button variable from ...

Rails: A good search algorithm

I'm trying to return results more like the search My curren algorithm is this def search_conditions(column, q) vars = [] vars2 = [] vars << q if q.size > 3 (q.size-2).times do |i| vars2 << q[i..(i+2)] next if i == 0 vars << q[i..-1] vars << q[0..(q.size-1-i)] vars << q[i % 2 == 0 ? (i/2)..(q...

Rails and Hobo with Single Table Inheritance problem

I'm getting an error when running db:setup for my Hobo project with a clean database. I have two models, A and B, where B extends A through single-table-inheritance. Creating everything works. But if I start with a fresh database, rake fails with an error: $ rake db:setup ... rake aborted! Table as does not exist Here are the steps I ...

Accesing data from httparty response

Using httparty I can get the following response: puts Representative.find_by_zip(46544).inspect --> {"results"=>[{"name"=>"Joe Donnelly", "district"=>"2", "office"=>"1218 Longworth", "phone"=>"(202) 225-3915", "link"=>"http://donnelly.house.gov/", "state"=>"IN"}] source of the example: http://railstips.org/blog/archives/2008/07/29/...

phusion passenger and ruby 1.9.1 is it working already?

i have a production and a development machine, both running ubuntu 8.10 and both are running the latest phusion passenger. as i am using ruby 1.9.1 on my local development machine on osx, i wondered if people out there are already using phusion passenger with ruby 1.9.1 or even 1.9.2 already? if so, please tell us your setup! furthermor...

Rails: In-place editor but no postback?

I'm using Prototype in my Rails project to do in-place editing (via Ajax.InPlaceEditor) of a form. However, I don't want it to immediately post back and do the update - the form itself is pretty complicated and the user may decide to abandon their changes. Only now they can't, because the form has invisibly (to them) updated the database...

Rails, page does not be rendered(just empty page) even though view and controller exist.

I'm following this article.(http://asciicasts.com/episodes/160-authlogic), I'm not using nifty generator tho. I've done with User model and 'localhost:3000/users/new' page works find. But 'localhost:3000/user_sessions/new' page does not work as I expected. I've just copied the source from the site. routes.rb map.login 'login', :contr...

Rails trying to send the id for a habtm model join table?

Hi, So I have two rails models - user and role - each specified with a habtm and a join table of users_roles. When I save from my user form, which has checkboxes for which roles to choose, rails is trying to manually insert a value into the id column of the join table. This doesn't make sense to me, as the id column should be set to au...

Paginate ordering doesn't work when using find_all_by_completed(false)

In my project model def incomplete @clients = current_user.clients.find_all_by_completed(false).paginate (:page => params[:page], :per_page => 10, :order => 'started_on DESC') end For some reason it doesn't order started_on descending. However ordering works in another method def all @clients = current_user.clients.paginate(:...

link_to image tag. how to add class to a tag

I am using link_to img tag like following <%= link_to image_tag("Search.png", :border=>0, :class => 'dock-item'), :action => 'search', :controller => 'pages'%><span>Search</span></a> Which results in following html <a href="/pages/search"><img alt="Search" border="0" class="dock-item" src="/images/Search.png?1264132800" /></a><span...

Images in a rails app not getting pushed to git

I have a simple app that I push to github. It contains images under public/images folder. Images are of extension .png I've pushed the code onto git hub and it got pushed w/out any errors. However, when I go to my repository from the browser...I do not see the images folder under public. Why are they being ignored? My .gitignore fil...

Rails has_one :through association

Rails has a has_one :through association that helps set up a one-to-one association with a third model by going through a second model. What is the real use of that besides making a shortcut association, that would otherwise be an extra step away. Taking this example from the Rails guide: class Supplier < ActiveRecord::Base has_one :...

Tips for rails blog

I'm looking for some blog that talks about ruby and rails. Any tips? Thanks ...

rake: Best way of handling an undefined parameter?

I've got a rake task on a rails app that needs one parameter, called USER_ID. I think I'd like to throw an exception that halts the execution. This is what my task looks like: desc "My rake task" task :my_task => :envionment do user_id = ENV["USER_ID"] or # THROW SOMETHING HERE # ... do stuff with user_id end What code goes on...

Wiki software that runs wiki.rubyonrails.org available for download?

Is the wiki software that runs http://wiki.rubyonrails.org/ available for download? I can't find it anywhere, thank you :) I've been investigating rails wikis, tried Instiki but still needs much work, other rails wiki suggestions welcome. ...

Reduce git repository size

I tried looking for a good tutorial on reducing repo size, but found none. How do I reduce my repo size...it's about 10 MB, but the thing is Heroku only allows 50 MB and I'm no where near finished developing my app. I added the usual suspects (log, vendor, doc etc) to .gitignore already. Although I only added .gitignore recently. Any s...

Apache RequestHeaders for Software-As-a-Service under Rails

Multiple customer instances of an application, under a single application. What I need is to allow multiple users, to connect to my Apache Web server, by passing different url like : customer1.myhost.com company1.myhost.com company2.myhost.com etc. What I want my Apache server to do, is pass all request that are not directed to a certa...

How do you handle SSL in development?

I have an application that uses HTTPS for some of its routes in conjunction with the ssl_requirement plugin. It's deployed and is working fine in production. The question is how best to handle this in development, because at the moment I'm simply hacking my routes.rb to remove the :requirements key and obviously that's not very convenie...