Questions tagged [ruby-on-rails-3]

Ruby on Rails is an open-source web development framework written in Ruby. Ruby on Rails follows the principle of convention over configuration, freeing you from having to re-invent things to stay productive. Use this tag only for Rails 3-specific questions, and also tag those questions [ruby-on-rails].

Ruby on Rails 3.0 was a major revision of Ruby on Rails in 2010, the open-source web development framework designed to make programmers happy and productive. Rails 3.0 brings a bunch of new features and improvements over older Rails versions, including:

  • Brand new router with an emphasis on RESTful declarations
  • New Active Record chainable query language built on top of relational algebra
  • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery
  • Explicit dependency management with Bundler

See Ruby on Rails 3.0 Release Notes for more information.

Multiple sub-versions have been released, namely 3.0, 3.1 and 3.2. Questions regarding specific sub-versions of Ruby on Rails 3.0 can also be asked on the appropriate tags:

Resources:

See also:

56082 questions
115
votes
8 answers

Devise password reset from Rails console

While running an app how do you select a user by email address and then set the password manually within rails console for Devise? Also, where would I go to review documentation to cover more details in this regard to manipulation of accounts while…
ylluminate
  • 12,102
  • 17
  • 78
  • 152
114
votes
2 answers

Rails - link_to helper with data-* attribute

Possible Duplicate: Best way to use html5 data attributes with rails content_tag helper? How can I use html5 data-* attrubute in my link_to helper (Rails) The API says that I have to use this format link_to(body, url, html_options = {}) but I…
eveevans
  • 4,392
  • 2
  • 31
  • 38
114
votes
5 answers

How do I strip non alphanumeric characters from a string and keep spaces?

I want to create a regex that removes all non-alphanumber characters but keeps spaces. This is to clean search input before it hits the db. Here's what I have so far: @search_query = @search_query.gsub(/[^0-9a-z]/i, '') Problem here is it removes…
TheExit
  • 5,220
  • 12
  • 37
  • 49
114
votes
3 answers

Turn off CSRF token in rails 3

I have a rails app that serves some APIs to an iPhone application. I want to be able to simply post on a resource without minding on get the correct CSRF token. I tried some methods that I see here in stackoverflow but it seems they no longer work…
Simone D'Amico
  • 2,335
  • 3
  • 17
  • 21
112
votes
24 answers

Best way to add "current" class to nav in Rails 3

I have some static pages in a navigation menu. I want to add a class like "current" to the item which is currently displaying. The way I am doing so is to add tons of helper methods (each for one item) to check the controller and action. def…
PeterWong
  • 15,951
  • 9
  • 59
  • 68
111
votes
4 answers

Rails - Validate Presence Of Association?

I have a model A that has a "has_many" association to another model B. I have a business requirement that an insert into A requires at least 1 associated record to B. Is there a method I can call to make sure this is true, or do I need to write a…
skaz
  • 21,962
  • 20
  • 69
  • 98
111
votes
4 answers

I need to generate uuid for my rails application. What are the options(gems) I have?

I use Rails 3.0.20 and ruby 1.8.7 (2011-06-30 patchlevel 352) Please suggest me the best plugin to generate guid.
Virtual
  • 2,111
  • 5
  • 17
  • 27
110
votes
9 answers

Thin web server: `start_tcp_server': no acceptor (RuntimeError) after git branch checkout

A Rails 3.2.0 app, working fine with Thin web server, both locally and on Heroku cedar stack. After: $ git branch work $ git checkout work $ rails server I get: => Booting Thin => Rails 3.2.0 application starting in development on…
maeseele
  • 1,101
  • 2
  • 8
  • 3
110
votes
13 answers

Heroku push rejected, no Cedar-supported app detected

I'm creating a Rails app with Rails 3.1.3: git init git remote add heroku git add . git commit -a -m "First commit" git push heroku master Got: Counting objects: 102, done. Delta compression using up to 4 threads. Compressing…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
110
votes
5 answers

How to show current year in view?

Is there a function I can use to show the current year in a view? I have tried <%= Time.now %> to try and show the time but this does not work for me.
Zakoff
  • 12,665
  • 5
  • 22
  • 35
110
votes
1 answer

curl json post request via terminal to a rails app

I'm trying to create a user on my rails app with a curl command from os x terminal. No matter how I format the data, the app returns a responses that non of my validations have passed. curl http://localhost:3000/api/1/users.json -i -X POST -d…
chris sun
  • 1,123
  • 2
  • 8
  • 5
110
votes
25 answers

PG undefinedtable error relation users does not exist

I saw this question up before, but only for rspec. I haven't created test yet because it's too advanced for me but one day soon i will! :P I get this error when I try to sign-up/login into my app. I used devise to create user and also omniauth2 to…
Naomi K
  • 1,437
  • 4
  • 13
  • 20
109
votes
3 answers

ActiveRecord find and only return selected columns

edit 2 If you stumble across this, check both answers as I'd now use pluck for this I have a fairly large custom dataset that I'd like to return to be echoe'd out as json. One part is: l=Location.find(row.id) tmp[row.id]=l but I'd like to do…
timpone
  • 19,235
  • 36
  • 121
  • 211
109
votes
5 answers

Use Rails’ form_for but set custom classes, attributes on
element?

form_for seems to ignore any 'extra' attributes like a data-foo attribute or class passed as options in its second argument. = form_for @user, {:url => 'foo', :class => 'x', 'data-bar' => 'baz' } do |f| # ... The output is a tag with no x…
Alan H.
  • 16,219
  • 17
  • 80
  • 113
108
votes
3 answers

How to comment lines in rails html.erb files?

Am a newbie to rails , please let me know the way to comment out a single line and also to comment out a block of lines in *.html.erb files.
Hemanth
  • 5,035
  • 9
  • 41
  • 59