ruby-on-rails3

How should I create a REST API using Rails 3.0?

I can't seem to find much information on the web about the different approaches to building a REST API in Rails; so I kinda have two questions: Can someone point me to some articles that show the pros/cons of the different approaches? Would you please share your thoughts on the pros/cons of the following approaches?   Proposed Appro...

Paperclip + Rails 3 + ActionMailer (receive) + s3

I am trying to save an image attachment sent to my rails app to s3 using paperclip however I am hitting these problems: Its getting to the attachment loop and failing with a NoMethodError (undefined method `size' for #<Mail::Part: 0x2b62856e8030>): app/mailers/user_mailer.rb:23:in `receive' app/mailers/user_mailer.rb:14:in `eac...

protected "reject" method firing with Rails 3 RC, Mongoid, and Recaptcha and RSpec

Please bear with me as I'm a bit new to rails (especially rails 3), and I'm kinda stumped by this. Basically I want to test my CustomersController in my application using RSpec. When I execute my specs trying to perform a post to the create action in my controller, I get this error, and I'm not sure why: 1) CustomersController as gues...

fields_for sending array instead of Hash (Rails 3)

I'm using fields_for in my form like so <%= form_for @user %> ... <%= f.fields_for :photos do |f2| %> <%= f2.radio_button :public, 'true' %> <% end %> ... <% end %> Here are the radio buttons it generates: <input id="user_photos_attributes_0_public_true" name="user[photos_attributes][0][public]" type="radio" value="true" ...

Erb encoding problem in Rails 3

Hi guys, I'm using Rails 3. I want to display generated html fragment inside erb template <%= "<div>Foo Bar</div>" %> Rails encodes div tags. If I'm correct in Rails 2 <%=h cause encoding. Seems that it was changed in Rails 3. How can insert html fragment without encoding in Rails 3? Regards, Alexey. ...

Does Rails 3 provide time based caching?

Hi guys, I need a timebased caching of certain pages. Cache for certain page should be cleared each 15 minutes. Is that possible? In http://edgeguides.rubyonrails.org/caching_with_rails.html manual I see that there is only manual cache clear methods, such as expire_page or expire_action. Regards, Alexey ...

Constructing URL parameters in Rails 3

I am trying to use the following code to convert a hash of options (e.g. { :opt1 => 'a', :opt2 => 'b' } ) into parameters to be appended to a URL (e.g. example.com/page?opt1=a&opt2=b): ActionController::Routing::Route.new.build_query_string(options) where options is the hash. I get the following error: wrong number of arguments (0 fo...

Best way to share features in Rails without reinvent the wheel

I begin with some examples that's better, when I plan a rails app I'd like to have: a SettingsController (to store system preferences, eg disqus id,..) with a model and some views a my custom template a login system (Devise) which is teh best practise to keep this components updated separatly? and indipendent from the new customized ...

rails3 session store

Hi, could you tell me plz - how to use in rails3 application external Active Record session store? In rails2 its simply ActiveRecord::SessionStore::Session.establish_connection("sessions_#{RAILS_ENV}") but wat about rails3? ...

how to include stylesheet in root folder of rails 3

Due to some heroku problems with rails 3 and compass framework, we followed this guide: http://lds.li/post/673242899/compass-with-rails-3-on-heroku and moved our stylesheets to app_name/tmp/stylesheets. I tried using stylesheet_link_tag "#{Rails.root}/tmp/stylesheets/main.css" but that doesnt work as it looks for the css file in ...

Single-user OpenID server with Rails

My website's root page automatically redirects all users to some subpage via http header. http://example.com/ → http://example.com/subpage I want to use my domain example.com as OpenID. The problem is that I have to add some tag to my root page, but it should redirect all users on subpage. I can change the type of redirection and use e...

How to use :conditions to compare (a datetime) with (datetime + 'number of days') ?

I'm building an application that checks when a user needs to change the oil of one of his cars. Here's how it works: The user enters the name of his car (e.g. 'Ford Mustang') The user enters the time the car will run on one oil change (e.g. 3.months) The user saves the car to the database Repeat above process for all his other cars. (Y...

Rails 3 rendering XML

I have Rails 3 application (running Rails RC1), and I have the following controller: class PluginsController < ApplicationController respond_to :html, :xml, :json def index @plugins = Plugin.all respond_with(@plugins) end end If I try to render http://localhost:3000/plugins it works fine, showing me the HTML version. If...

Authorization plugins for RoR with Rails 3 support

Hi guys, Please name RoR authorization plugins with Rails 3 support, which you think is the best. Regards, Alexey Zakharov ...

rails 3 swf_upload InvalidAuthenticityToken and sending cookie session

Hi guys. I have a swfupload working with paperclip on rails 3 (finally!) I turned off the autehnticitytoken with the following line in my controller: skip_before_filter :verify_authenticity_token, :only => :create I know am trying to get sessions working (flash doesn't send this) Of course i googled my ass of but no luck so far. thi...

Rails3 ajax upload with Iframe

Hi, before rails3 I had a working multiple ajax(mootools) file upload solution. I used form_to_remote with an iframe and responds_to_parent. In rails3 the ajax upload with form_tag remote => true, traget => "my_iframe" doesn't work. The the param[:uploaded_image]with the file is missing. I don't know why. Can anyone recommend a good a...

Undefined local variable or method `_setup_mocks' in cucumber 0.8.5 and rspec2

Inside of : features/support/env.rb require 'cucumber/rspec/doubles' I just ported my project to a new cpu and it's returning this error on everything: undefined local variable or method `_setup_mocks' I'm guessing I'm missing something. Gems : rspec (2.0.0.beta.18) rspec-core (2.0.0.beta.18) rspec-expectations (2.0.0.beta.18) rs...

Rails 3 RSpec 2 NetBeans integration

NetBeans 6.9 provides a custom Runner class for RSpec to be integrated into the IDE. I'm trying to get my Rails 3 applications specs to be correctly displayed inside NetBeans, but RSpec 2 seems no longer to support custom Runner classes in general. Any ideas how to get the specs into the IDE anyway? ...

Rails partial overloaded with logic needs refactor

How would you refactor this logic filled partial? <%- for post in @posts -%> <div class="post"> <%= link_to post.title, post %> <%- if post.name.empty? -%> <%- else -%> <span class="name"> by <%- if post.email.blank? -%> <%= post.name %> <%- else -%> <a href="mailto:<...

Combine two ActiveRecord Query results

I currently have two active record queries that I would like to combine together joins("join relationships ON user_id = followed_id"). where("follower_id = #{user.id}") and where(:user_id => user.id) Basically I want the results of the second one to appear with the first similar to a UNION statement in SQL. Can it b...