ruby-on-rails3

Has anyone used Minitest::Spec withing a Rails functional test?

The spec library in Minitest is great. I've been able to use it within Rails unit tests no problem. However, Rails functional test inherit from ActionController::TestCase which provides instance variables like @controller in it's setup. Has anyone been using the Minitest::Spec lib for their Rails functional tests? If not, I'm conside...

How to determine link_to path arguments for nested resources?

How do I determine the link_to arguments for show, edit, and destroy? I know "new" is "new_user_post_path". Nothing else seems to follow this convention though? My relevant routes.rb snippet: resources :users do resources :posts end ...

Need help with my rails 3 environment

pulled down a repo from git. For some reason I need to do ./script/rails.rb s where on the rails 3 ap I started on my box, I can just do the rails server can anyone help me set up my environment so I don't have to do this? I'm still trying to figure out what I need to type to do a migration... ...

How to make US date format as the default when saving to a model in Rails 3

The US date used to be accepted/parsed correctly, but not anymore in Rails 3. The %Y-%m-%d is accepted but not %m/%d/%Y. g = Grant.new g.budget_begin_date = '12/31/2010' #g.budget_begin_date returns nil g.budget_begin_date = '2010-12-31' #g.budget_begin_date returns Fri, 31 Dec 2010 00:00:00 UTC +00:00 ...

Why is this nested resource link_to looking for "destroy" instead of "show"?

I'm just trying to get the link to point to "user/1/post/1". I've tried using the link_to with and without the :method key and got the same results. ActionController::RoutingError in Posts#index Showing /home/test/rails_apps/test_app/app/views/posts/index.html.erb where line #22 raised: No route matches {:action=>"destroy", :controll...

How to redirect without www using Rails 3 / Rack?

I understand there are a lot of questions that answer this. I'm familiar with .htaccess and nginx.conf methods, but I do not have access to such traditional configuration methods on heroku. Simone Carletti gave this answer that leverages Rails 2.x Metals, but I'm using Rails 3 and this isn't compatible. http://stackoverflow.com/questio...

Undefined name method test error in Rails3

Working through Michael Hartl's RailsTutorial and came across the following error - even though I have followed everything to the 'T'. 1) UsersController GET 'index' for signed-in users should have an element for each user Failure/Error: response.should have_selector("li", :content => user.name) undefined method `name' for #<Array:0x000...

Rails 3 - select with Include?

I've been looking for how to do a select with include in Rails 3 - I have a nested example: @items = Item.where("fulfilled = ?", true).includes({:order=>[:supplier, :agent]}, :manufacturer) This is a very taxing query to run without selects as it creates 1000s of rows of data by pulling information from all the above big tables. How ca...

How to do user content from CMS in Rails

I'm trying to build a CMS in Rails from scratch, and for showing the user generated pages I'm having trouble deciding exactly how to do it. The way I have it right now, I have a controller named 'content' with a single action called 'show'. In routes.rb I have a rule that passes any name after the name of the website to the content con...

Rails 3 - Time Comparison?

Hello, I'm working to do the following in my Rails App: if record.updated_at > 15.minutes.ago do some stuff end Meaning... If the record.updated_at was over 15 minutes ago, do some stuff... This doesn't seem to be working. Ideas? ...

Rails - Making @projects avaialble on all page loads

Hello, On every page of my app I want to show a user's projects... So which controller do I use to make sure that @projects from the projects controller is being made available in the view? Thanks ...

Rails - Passing an option variable in a partial

Hello, I'm building a header partial for a view. I call the partial as following: <%= render :partial =>"project/header", :locals => {:right_header => 'BLAH BLAH'} %> The header has a default right_header, but I'd like the option to overwrite it: <div id="header"> <span class="right"> Standard Header here </span> </div> The deal i...

Direct downloading a xls file without writing it to the directory by Spreadsheet gem

I am using this Spreadsheet gem to export xls file. I have the following codes in my controller: def export @data = Data.all book = Spreadsheet::Workbook.new sheet = book.create_worksheet :name => "data" contruct_body(sheet, @data) book.write "data.xls" end In this way, I can fill in the data and save it in the root dire...

How to access validation messages in partials?

So, each rails project i seem to run into this problem and would be really grateful if someone could enlighten me: With a "normal" setup when the form sits on the view immediately associated with the url/controller it is pretty straightforward, a render => :action on fail will display the validation message. Now what i have is a form i...

rails how to check an model object has persistenced to db or a new object

e.g. c=Category.new this is didn't persistence to db, how to distinguish a object wheather persistenced to db yet ...

Does anyone know of a rails gem for managing bibliography/references?

Hi, Does anyone know of a gem/plugin for rails which can be used to manage bibliography or publication references? This tends to be quite standard format, so I am hoping there is something out there? thanks ...

rails password update issue

Hi, I am making a update password module for an application in rails. Now the problem is that I am encrypting the password before_save, and it is required that the password be between 6 to 20, so after encryption the password becomes 64 chars, but since the encryption happens after validations, the code works. Now when I want to update ...

What is the equivalent of script/destroy scaffold User in Rails 3?

When I was using Rails 2, I did script/generate scaffold User to create the user model. Now I need to remove it, and I'm using Rails 3. I tried rails destroy scaffold User and rails destroy User, but these just created new rails projects named destroy. How do I do it? Thanks for reading. ...

Rails: remove port from _url helper

Hi, When calling the _url helper in rails it will return host+port+path so for example photo_url will return http://localhost:3000/photo In my production environment I have thin serving the rails application on a given port and apache serving static content on another port. When the site is accesed without any port each server kno...

Autotest not running in Ruby 1.9.2, only 1.8.7

UPDATE: It works now. I truly don't know what happened. I'll leave this Q up for some time, in case other experience the same. If not, I'll soon delete it. TLDR: autotest rspec works with ruby1.8.7 but not in ruby1.9.2. Using rails3, rspec2, autotest 4.4.1. In 1.9.2, it doesn't do anything after starting autotest. OK, now I'm real tire...