Git Product home page Git Product logo

rails's Introduction

Welcome to Rails

What's Rails?

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers: Model, View, and Controller, each with a specific responsibility.

Model layer

The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.

View layer

The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (ERB files). Views are typically rendered to generate a controller response or to generate the body of an email. In Rails, View generation is handled by Action View.

Controller layer

The Controller layer is responsible for handling incoming HTTP requests and providing a suitable response. Usually, this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and manipulate models, and render view templates in order to generate the appropriate HTTP response. In Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and controller classes are derived from ActionController::Base. Action Dispatch and Action Controller are bundled together in Action Pack.

Frameworks and libraries

Active Record, Active Model, Action Pack, and Action View can each be used independently outside Rails.

In addition to that, Rails also comes with:

  • Action Mailer, a library to generate and send emails
  • Action Mailbox, a library to receive emails within a Rails application
  • Active Job, a framework for declaring jobs and making them run on a variety of queuing backends
  • Action Cable, a framework to integrate WebSockets with a Rails application
  • Active Storage, a library to attach cloud and local files to Rails applications
  • Action Text, a library to handle rich text content
  • Active Support, a collection of utility classes and standard library extensions that are useful for Rails, and may also be used independently outside Rails

Getting Started

  1. Install Rails at the command prompt if you haven't yet:

    $ gem install rails
  2. At the command prompt, create a new Rails application:

    $ rails new myapp

    where "myapp" is the application name.

  3. Change directory to myapp and start the web server:

    $ cd myapp
    $ bin/rails server

    Run with --help or -h for options.

  4. Go to http://localhost:3000 and you'll see the Rails bootscreen with your Rails and Ruby versions.

  5. Follow the guidelines to start developing your application. You may find the following resources handy:

Contributing

We encourage you to contribute to Ruby on Rails! Please check out the Contributing to Ruby on Rails guide for guidelines about how to proceed. Join us!

Trying to report a possible security vulnerability in Rails? Please check out our security policy for guidelines about how to proceed.

Everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails code of conduct.

License

Ruby on Rails is released under the MIT License.

rails's People

Contributors

amatsuda avatar byroot avatar carlosantoniodasilva avatar dhh avatar drogus avatar eileencodes avatar fxn avatar georgeclaghorn avatar guilleiguaran avatar jeremy avatar jonathanhefner avatar jonleighton avatar josevalim avatar josh avatar kamipo avatar kaspth avatar lifo avatar matthewd avatar miloops avatar nzkoz avatar pixeltrix avatar rafaelfranca avatar senny avatar sgrif avatar spastorino avatar tenderlove avatar vijaydev avatar vipulnsward avatar y-yagi avatar yahonda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails's Issues

textarea helper swallows leading newline

Browsers swallow the first newline after a textarea tag, as per the HTML spec. The text_area helpers in Rails do not emit a newline after the textarea tag and this has the unintended side effect that if the contents of the tag happens to start with a new line it will get eaten by the browser.

It's easy to reproduce by inserting a new line or two in a text area field in any rails app and then updating it (the newline only gets eaten on the second trip to the browser, so updating is necessary). It's not really possible to produce a failing unit test as this requires an actual browser to do the swallowing.

(I looked through the code for a fix but the helper seems to delegate the generating of the actual tag to a generic "content tag" function. It would be ugly to make that content tag function behave differently for just one tag, so it seems that making the text_area helpers emit their own HTML would be the most straightforward option)

Rails::Server outputs 'http://' even when running over SSL

Rails always outputs "Rails application starting in on http://" even when the server is running over SSL.

From:
https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server.rb#L57

    def start
      puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
      puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
      puts "=> Call with -d to detach" unless options[:daemonize]
      [...]

Rack::Server supports the :SSLEnable option and it would be nice if Rails did a simple check to output the right protocol handler string.

I agree it is not common to use the :SSLEnable option, but since it is available and the fix would be very easy to add I reckon it's worth a try. For an example on how we configure SSL in the Dradis Framework:

http://dradis.svn.sourceforge.net/viewvc/dradis/server/trunk/script/rails?view=markup

If you are keen on addressing this, I'm happy to fork / patch and send a pull request. Just let me know.

Bug in corelib.rubyonrails.org String documentation

The bug's in the documentation for slice! :

string = "this is a string"
string.slice!(2) #=> 105
string.slice!(3..6) #=> " is "

Whereas the last line is supposed to be:

string.slice!(4..7) #=> " is "

Thanks,
Osman

Ignore

This issue has been removed.

Rakefile depends on gems from :test. Production deployment without them impossible

I'm dealing with the following scenario:
I deploy a RoR app (using Capistrano). I instruct Bundler to leave out the :development and :test groups, because these gems should not be needed in production. Nevertheless, I need my Rakefile to be usable, because there are rake tasks I need to be able to execute, such as 'rake db:migrate'. Currently, this is not the case: several generate/install actions installed tasks to lib/tasks, a directory that is of course deployed to production with the rest of the code, and these tasks, such as the Cucumber task, depend on gems from the :test group.

I'm assuming you agree that it is better not to have the gems from :development and :test available in production. I think the best solution is to not include 'lib/tasks' when Rails is running with Rails.env == :production.

Polymorphic has_many through association causes nil in join table

I have stumbled upon a problem with Rails 3.0.7 that I have not found a solution for, and to me it seems like a bug. If it's not, please be gentle. :)

My models contains of a Notification class that are connected to Group and Member via a polymorphic join model called Delivery. The problem is that when I do the following, the Delivery object is saved, but it fails to add the key to the new notification object.

The flow in the application, for this example is:

  1. /members/new
    Creating a new member
  2. /members/1/notifications/new
    Creating a new notification object by creating a notification object, adding the parent member to the members association and then saving the notification object. As I understand the documentation, the Delivery join object should automatically be saved after the notification object has been saved to the database (and an ID is given to the notification object).

After saving the notification, the Delivery join object is also saved, but the Delivery table in the database does not contain the id of the newly created notification object:

select id, notification_id, notifiable_type, notifiable_id from deliveries; 
1|<NULL>|Member|1

Note: I worked around the problem by calling notification.save before notification.members << member, but this causes my after_save callbacks to run prematurely, before the notification object is in a valid state.

Example code from my application. Using this code results in the null value in the delivery table.

class Notification < ActiveRecord::Base
  has_many :deliveries, :as => :notifiable
  has_many :members, :through => :deliveries, :source => :notifiable, :source_type => "Member"
  has_many :groups, :through => :deliveries, :source => :notifiable, :source_type => "Group"
end

 class Member < ActiveRecord::Base
  has_many :deliveries, :as => :notifiable
  has_many :notifications, :through => :deliveries
end

class Delivery < ActiveRecord::Base
  belongs_to :notification
  belongs_to :notifiable, :polymorphic => true
end

# Group is not really relevant in this example.
class Group < ActiveRecord::Base 
  has_many :deliveries, :as => :notifiable
  has_many :notifications, :through => :deliveries
end

class NotificationsController < ApplicationController
  def create
    @notification = Notification.new(params[:notification])
    @member = Member.find(params[:member_id])
    @notification.members << @member

    respond_to do |format|
      if @notification.save
        ...
      end
    end
  end
end

Using non-polymorphic join model worked as expected

Trying to identify if the polymorphic association was the origin of the problem, I simplified my model using only a simple non-polymorphic join model. This worked as expected, and the notification_id was set correctly in the delivery table without the need for "double saving" the notification object.

select id, notification_id, member_id from deliveries; 
1|1|1

Working code, without the many-to-many polymorphic join model:

class Notification < ActiveRecord::Base
  has_many :deliveries
  has_many :members, :through => :deliveries
end

class Member < ActiveRecord::Base
  has_many :deliveries, :as => :notifiable
  has_many :notifications, :through => :deliveries
end

class Delivery < ActiveRecord::Base
  belongs_to :notification
  belongs_to :member
end

class NotificationsController < ApplicationController
  def create
    @notification = Notification.new(params[:notification])
    @member = Member.find(params[:member_id])
    @notification.members << @member

    respond_to do |format|
      if @notification.save
        ...
    end
  end
end

scss

Hi there's an issue with SCSS in Rails 3.1 beta 1.

It can't seem to read mixin's.

What I did was use the command for now:

sass --watch app/assets/stylesheets:app/assets/stylesheets --trace

Rails fails to start (rails master + sprockets master)

=> Booting WEBrick
=> Rails 3.1.0.beta1 application starting in development on http://0.0.0.0:3001
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/actionpack/lib/sprockets/railtie.rb:37:in `block (2 levels) in ': undefined method `context' for Sprockets::Environment:0x00000002535fa0 (NoMethodError)
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/actionpack/lib/sprockets/railtie.rb:36:in `block in '
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:34:in `call'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/application/finisher.rb:56:in `block in '
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/initializable.rb:25:in `instance_exec'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/initializable.rb:25:in `run'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/initializable.rb:49:in `each'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/initializable.rb:49:in `run_initializers'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/application.rb:94:in `initialize!'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/railtie/configurable.rb:28:in `method_missing'
    from /home/user/work/testapp/config/environment.rb:5:in `'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:237:in `require'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:237:in `block in require'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/activesupport/lib/active_support/dependencies.rb:237:in `require'
    from /home/user/work/testapp/config.ru:4:in `block in '
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/builder.rb:51:in `instance_eval'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/builder.rb:51:in `initialize'
    from /home/user/work/testapp/config.ru:1:in `new'
    from /home/user/work/testapp/config.ru:1:in `'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/builder.rb:40:in `eval'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/builder.rb:40:in `parse_file'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/server.rb:200:in `app'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/commands/server.rb:46:in `app'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/server.rb:301:in `wrapped_app'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rack-09433a26a9e6/lib/rack/server.rb:252:in `start'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/commands/server.rb:70:in `start'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/commands.rb:54:in `block in '
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/commands.rb:49:in `tap'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-67c3469e6ff1/railties/lib/rails/commands.rb:49:in `'
    from script/rails:6:in `require'
    from script/rails:6:in `'

Status: 500 Internal Server Error private method `split' called for Mime::Type in

When request with headers:

Accept application/json,application/javascript
Content-Type application/json
X-Requested-With XMLHttpRequest

We get on server:
Status: 500 Internal Server Error
private method split' called for #<Mime::Type:0xb743a2a8> /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_type.rb:206:inmethod_missing'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:51:in media_type' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:117:inparseable_data?'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:138:in POST' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:428:inrequest_parameters'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:381:in parameters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:1279:inassign_shortcuts'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:518:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606:insass_old_process'
/usr/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/sass/plugin/rails.rb:19:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:65:incall_with_exception'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:91:in dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:111:in_call'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:82:in initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:incall'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:incache'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:incall'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/head.rb:9:incall'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:24:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:incall'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:93:incall'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:incall'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:insynchronize'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:incall'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:incall'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in each' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:incall'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb:17:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:incall'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/chunked.rb:15:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:61:inprocess'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:ineach'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:inrun'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:innew'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:ininitialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:inrun'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:34:in run' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

Rails 3 deleting a cookie AND calling reset_session does not send new session ID

Rails 3.0.7, ruby-1.9.2 (via RVM). Take the following code:

class LoginController < ApplicationController
    # ... SNIP ... 

    def destroy
        cookies.delete(:secureusertokens)
        reset_session
        redirect_to root_url
    end
end

This is simply a logout. It resets the session and deletes any "remember me" cookie that may be set.

Unfortunately, while a new session ID is generated, the Set-Cookie: header lacks this information (presumably because the session logic has a reference to some stale cookie data, and the controller overwrites it).

The session key is just SESSID in these headers.

In the request:

Cookie: hiddenalerts=site_vrfy_124258; __utmz=REMOVED_INFO.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); elpriv=REMOVED_INFO; SESSID=b39a9a89bb6a39ea91b620fe0da392ed; __utma=REMOVED_INFO; __utmc=REMOVED_INFO; __utmb=REMOVED_INFO

And in the response (no mention of the newly generated session ID):

Set-Cookie: secureusertokens=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Now if I remove the call to cookies.delete(...) in the controller.

In the request (identical):

Cookie: hiddenalerts=site_vrfy_124258; __utmz=REMOVED_INFO.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); elpriv=REMOVED_INFO; SESSID=b39a9a89bb6a39ea91b620fe0da392ed; __utma=REMOVED_INFO; __utmc=REMOVED_INFO; __utmb=REMOVED_INFO

And in the response (correct!!):

Set-Cookie: SESSID=50640523cf32b5b0fe8c93eb16aba6dc; path=/; HttpOnly

It seems that I can either have the new session ID sent, or the "remember me" cookie deleted, but not both. I can work around this by manually sending the new cookie, but it seems like a bug to me ;)

I have my own custom SessionStore (MemCache + MySQL), but it does not set these cookies, that happens elsewhere.

ActiveRecord Observer around callbacks do not receive a block to yield to

ActiveRecord Observer around_* callbacks are broken at the moment. Trying to yield from them results in a "no block given (yield)" error. The around callbacks on the model itself works.

I.e. this work:

class Foo < ActiveRecord::Base
around_save :do_around_save
def do_around_save(foo)
yield
end
end

This does not:

class Foo < ActiveRecord::Base
end

class FooObserver < ActiveRecord::Observer
def around_save(foo)
yield
end
end

Running 3.0.7.

ActiveRecord Fixture class (lighthouse issue 6098)

https://rails.lighthouseapp.com/projects/8994/tickets/6098-activerecord-fixture-class

Reported by Brian Underwood | January 18th, 2011 @ 08:52 AM | in 3.1
This is more of a question for the moment.

I'm working on a large Rails app which, unfortunately, has a Fixture model. I'm running into issues where the Fixture class (used for test fixtures) is extending our Fixture model class and causing issue with testing our Fixture model (we've long neglected testing and are just now building up our suite).

I took a look at the ActiveRecord source and the Fixture class seems to be relatively limited in it's usage. It would be much less work to namespace the Fixture class in ActiveRecord than to change all of the various references to the Fixture model in our app (and it would allow other Rails users to have 'Fixture' models). I'd be happy to work on a patch to do this, but I wanted to get advice first and make sure that it would be a good way to go. Should I namespace it in the ActiveRecord module? Should I namespace all of the classes in the fixtures.rb file?

ActiveRecord :has_many with :finder_sql generates invalid query

To ilustrate issue, create 2 models:

Parent (id, name)
class Parent < ActiveRecord::Base
has_many :childs
has_many :finder_childs, :class_name => 'Child', :finder_sql => 'SELECT * from children WHERE parent_id=#{id}'
end

Child(id, name, parent_id)
class Child < ActiveRecord::Base
end

p = Parent.first
p.childs.all.map(&:id) # works ok
p.finder_childs.all.map(&:id) # raises sql exception because of invalid query

Last line generates exception in sqlite and mysql. Error for sqlite:
SQLite3::SQLException: only a single result allowed for a SELECT that is part of an expression: SELECT "children".* FROM "children" WHERE (SELECT * from children WHERE parent_id=1)

using p.finder_childs.map(&:id) works fine.

Dynamic find_or_create_by_x_and_y calls always create a new record in Rails 2.3.11

This is a regression that was introduced in fdfc8e3.

Any create_or_find_by_x_and_y call on an association will aways create a new record.

To recreate:

Say you have two models, one has_many of another:

class Author < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :author
end

Jump into the console and enable AR logging. Then run the dynamic find_or_create_by twice:

Author.first.posts.find_or_create_by_title_and_published('Post Title, true)
Author.first.posts.find_or_create_by_title_and_published('Post Title, true)

You'll see that the query looks generates something like

select * from posts where title IN ('Post Title', 1) and published = '' and author_id = 7

i.e. the title is getting passed an array of the input.

Failing test and patch coming shortly...

ActionMailer OldApi clobbers mime boundary header

Using the content_type method from the OldApi of action mailer, the generated mail will be missing a boundary declaration in the Content-type header. This hinders parsing of the email content by us using the Mail gem, and by email clients.

e.g.

Expected header:

Content-Type: multipart/alternative;
 boundary="--==_mimepart_4dbe43822262f_1835800eb1381673f";
 charset=UTF-8

Actual header:

Content-Type: multipart/alternative

I've posted a sample 3.0.7 rails project on https://github.com/kuahyeow/test_actionmailer that shows the failing test. Run rake test to see the one failure.

STI with multiple models is 'lazy loaded'

Having 3 models using STI:

class Low < Medium; end

class Medium < High; end

class High < ActiveRecord::Base; end

If I run Medium.all, the SQL ActiveRecord outputs looks for records on the highs table with type='Medium', and as such doesn't find any records for 'Low' objects.

Afterwards, If I try High.all and then Medium.all, then it successfully looks for records with type='Medium' or type='Low'.

Fix failing test in xml_mini_test.rb

This failing test is a result of some duplicate test names and the fact that some of the tests for XmlMini weren't getting run.

See #449 for a bit more information.

The regex that is handling the code for the failing test is above my head right now.

Will take a look when I have more time unless someone gets to it before me.

Can't run rake

I've started a new rails project using rails 3.1beta1 and when I try to run any rake command (I've tested rake db:migrate, rake spec and rake -T) I get the following error/warnings:

WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
rake aborted!
stack level too deep

(See full trace by running task with --trace)

I created a new project without any non-rails dependences and tested the rake commands and the same thing happens, When I remove the all rails requires in the Rakefile rake runs normally. I've also tried using the master branch (gem 'rails', :git => 'git://github.com/rails/rails.git') and yet again the same thing happens.

We need rails.lighthouseapp.com back to public

As of right now, we can't see the content of https://rails.lighthouseapp.com/ and instead it tells us "Oops! : You must be a member of this account".

Disabling new tickets there is fine, but making the entire content private? No, no, please.

We have lots of links from our source code to the permalinks on rails.lighthouseapp.com, to explain rationale for patches, etc. and that includes my own comments. We have patches for like TimeZone, ActiveSupport::JSON::Encoding, ActionDispatch::Http::MimeNegotiation, ActionDispatch::ShowExceptions, etc. and losing those information could lead to lots of duplicated efforts.

If you can't get back this to public, at least let us download some of the tickets in there.

Sprockets doesn't work alongside with catch-all routes

This is a copy of: https://rails.lighthouseapp.com/projects/8994/tickets/6768-assets-route-should-not-be-prefixed

Long story short, the moment I introduce a catch-all route like this:

match '/*', :to => 'test#test'

Sprockets won't serve anything as /assets is taken over by my route. Before rake routes would actually show that sprockets relates routes come after my application routes. Now it won't show anything but I'm sure those routes are attached after. I think Sprockets routes have to be attached before any application/engines routes.

I'd fix it myself, but I have no idea where to look. Thanks.

Use PATCH verb instead of PUT for "update"

Rails should map the PATCH HTTP verb to the update action to respect proper HTTP/REST semantics.

The current mapping of PUT to update is an imprecise mapping of HTTP verbs ("REST") to CRUD. PUT more accurately means "place" or "replace", and can even be used to create new records at a specific URI.

From the HTTP specs for PATCH:

The PUT method is already defined to overwrite a resource
with a complete new body, and cannot be reused to do partial changes.
Otherwise, proxies and caches, and even clients and servers, may get
confused as to the result of the operation.

Furthermore, Rails convention for the update action is not idempotent--a requirement for PUT according to the specs.

As a solution, I propose that PATCH requests be routed to the update action alongside PUT. Furthermore, PATCH should be made the default form method when editing existing model records, since 99% of the time, users want to modify an existing record instead of replacing it. In later versions, PUT can be deprecated or mapped to a different action with proper semantics.

This change should not break browser compatibility since browsers are already using _method param override for PUT; changing that to PATCH should be simple. Furthermore, leaving the default PUT routing (alongside PATCH) in restful routes should make this change backwards compatible for most users.

If this is something the core developers agree with, I can contribute a ... um ... patch.

Reference: http://tools.ietf.org/html/rfc5789

Unnecessarily slow PostgreSQLAdapter#columns

The PostgreSQLAdapter's "columns" method creates a new PostgreSQLColumn object for every column of a given database table. However, the constructor for this class has this form:

def initialize(name, default, sql_type = nil, null = true)
  super(name, self.class.extract_value_from_default(default), sql_type, null)
end

The 'default' parameter is a string describing a SQL data type whenever the DB column has a default value, however it is nil all the other times, that is: most of the time. Now, the extract_value_from_default method looks like this:

def self.extract_value_from_default(default)
  case default
    # Numeric types
    when /\A\(?(-?\d+(\.\d*)?\)?)\z/
      $1
    # Character types
    when /\A'(.*)'::(?:character varying|bpchar|text)\z/m
      $1
   ....
  end
end

Unfortunately it doesn't check for a nil anywhere, so it ends up calling === against nil for every 'when' clause in this method. It ends up causing a major performance issue especially:

a) in the development environment where this is called on every request
b) for complex schemas where there are many tables/columns

In my case, it made every request in development mode twice as slow. The same issue may affect other DB adapters. It doesn't affect ActiveRecord 2.3.10, and I think the reason for this might be the difference between NilClass#method_missing implementation between ActiveSupport 2.3.10:

def method_missing(method, *args, &block)
  # Ruby 1.9.2: disallow explicit coercion via method_missing.
  if method == :to_ary || method == :to_str
    super
  elsif klass = METHOD_CLASS_MAP[method]
    raise_nil_warning_for klass, method, caller
  else
    super
  end
end

And ActiveSupport 3.0.6:

def method_missing(method, *args, &block)
  if klass = METHOD_CLASS_MAP[method]
    raise_nil_warning_for klass, method, caller
  else
    super
  end
end

This fix for Ruby 1.9.2 was introduced by Jeremy Kemper in this commit: 9acc824 and I don't know what happened with it since and why.

An easy fix would be to modify PostgreSQLAdapter#initialize like this:

def initialize(name, default, sql_type = nil, null = true)
  default_value = default.present? ? self.class.extract_value_from_default(default) : nil
  super(name, default_value, sql_type, null)
end

I am on Ruby 1.9.2.

default_scope adds order clause to aggregation queries

For example:

class User
def self.default_scope; order('created_at DESC'); end
end

User.count # SELECT COUNT(*) FROM "users" ORDER BY created_at DESC

I've only tested this using the postgresql adapter and rails 3.1.0.beta1

XML Mini tests (test_xml_mini.rb) don't seem to get run

Output of running the tests for activesupport don't include test/test_xml_mini.rb.

[@1.9.2@rails3dev ][xxxxx@xxxxx(master)]$ rake test
(in /Users/xxxx/Documents/Development/rubyDevelopment/rails_source/rails/activesupport)
/Users/xxxx/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -w -I"lib:test" "/Users/xxxx/.rvm/gems/ruby-1.9.2-p180@rails3dev/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/benchmarkable_test.rb" "test/buffered_logger_test.rb" "test/caching_test.rb" "test/callback_inheritance_test.rb" "test/callbacks_test.rb" "test/class_cache_test.rb" "test/clean_backtrace_test.rb" "test/clean_logger_test.rb" "test/concern_test.rb" "test/configurable_test.rb" "test/core_ext/array_ext_test.rb" "test/core_ext/base64_ext_test.rb" "test/core_ext/bigdecimal_test.rb" "test/core_ext/blank_test.rb" "test/core_ext/class/attribute_accessor_test.rb" "test/core_ext/class/attribute_test.rb" "test/core_ext/class/class_inheritable_attributes_test.rb" "test/core_ext/class/delegating_attributes_test.rb" "test/core_ext/class_test.rb" "test/core_ext/date_ext_test.rb" "test/core_ext/date_time_ext_test.rb" "test/core_ext/duplicable_test.rb" "test/core_ext/duration_test.rb" "test/core_ext/enumerable_test.rb" "test/core_ext/file_test.rb" "test/core_ext/float_ext_test.rb" "test/core_ext/hash_ext_test.rb" "test/core_ext/integer_ext_test.rb" "test/core_ext/kernel_test.rb" "test/core_ext/load_error_test.rb" "test/core_ext/module/anonymous_test.rb" "test/core_ext/module/attr_accessor_with_default_test.rb" "test/core_ext/module/attr_internal_test.rb" "test/core_ext/module/attribute_accessor_test.rb" "test/core_ext/module/attribute_aliasing_test.rb" "test/core_ext/module/reachable_test.rb" "test/core_ext/module/synchronization_test.rb" "test/core_ext/module_test.rb" "test/core_ext/name_error_test.rb" "test/core_ext/numeric_ext_test.rb" "test/core_ext/object/inclusion_test.rb" "test/core_ext/object/to_param_test.rb" "test/core_ext/object/to_query_test.rb" "test/core_ext/object_and_class_ext_test.rb" "test/core_ext/proc_test.rb" "test/core_ext/range_ext_test.rb" "test/core_ext/regexp_ext_test.rb" "test/core_ext/string_ext_test.rb" "test/core_ext/time_ext_test.rb" "test/core_ext/time_with_zone_test.rb" "test/core_ext/uri_ext_test.rb" "test/dependencies_test.rb" "test/deprecation/proxy_wrappers_test.rb" "test/deprecation_test.rb" "test/descendants_tracker_with_autoloading_test.rb" "test/descendants_tracker_without_autoloading_test.rb" "test/file_update_checker_test.rb" "test/flush_cache_on_private_memoization_test.rb" "test/gzip_test.rb" "test/i18n_test.rb" "test/inflector_test.rb" "test/isolation_test.rb" "test/json/decoding_test.rb" "test/json/encoding_test.rb" "test/lazy_load_hooks_test.rb" "test/load_paths_test.rb" "test/log_subscriber_test.rb" "test/memoizable_test.rb" "test/message_encryptor_test.rb" "test/message_verifier_test.rb" "test/multibyte_chars_test.rb" "test/multibyte_unicode_database_test.rb" "test/multibyte_utils_test.rb" "test/notifications_test.rb" "test/option_merger_test.rb" "test/ordered_hash_test.rb" "test/ordered_options_test.rb" "test/rescuable_test.rb" "test/safe_buffer_test.rb" "test/secure_random_test.rb" "test/string_inquirer_test.rb" "test/test_case_test.rb" "test/test_test.rb" "test/time_zone_test.rb" "test/transliterate_test.rb" "test/whiny_nil_test.rb" "test/xml_mini/jdom_engine_test.rb" "test/xml_mini/libxml_engine_test.rb" "test/xml_mini/libxmlsax_engine_test.rb" "test/xml_mini/nokogiri_engine_test.rb" "test/xml_mini/nokogirisax_engine_test.rb" "test/xml_mini/rexml_engine_test.rb"

Parameter Filter not working

I have a very simple testing app, containing login code only.

On the login action I added a debugger to check if Rails is filtering the parameters as it should.
I did:

(rdb:1) eval env["action_dispatch.parameter_filter"]
[:password, :password, :password_confirmation, /RAW_POST_DATA/]

So it should filter the password. Checking it like this works fine

eval ActionDispatch::Request.new(env).filtered_parameters
{"commit"=>"Sign in", "action"=>"create", "utf8"=>"✓", "authenticity_token"=>"8VJfRG+0RHI2u1Lp0BvbP3ee9023TQFfdkVYmiaI6D4=", "controller"=>"devise/sessions", "user"=>{"remember_me"=>"0", "password"=>"[FILTERED]", "email"=>"[email protected]"}}

The problem is when I do:

eval ActionDispatch::Request.new(env).filtered_env

It shows the entire env that should be filtered, and in several places it is, but I see parts like this:

[...]
"action_dispatch.request.request_parameters"=>{"commit"=>"Sign in", "authenticity_token"=>"8VJfRG+0RHI2u1Lp0BvbP3ee9023TQFfdkVYmiaI6D4=", "utf8"=>"✓", "user"=>{"remember_me"=>"0", "password"=>"user123", "email"=>"[email protected]"}},
"rack.request.form_vars"=>"utf8=%E2%9C%93&authenticity_token=8VJfRG%2B0RHI2u1Lp0BvbP3ee9023TQFfdkVYmiaI6D4%3D&user%5Bemail%5D=user%40test.com&user%5Bpassword%5D=user123&user%5Bremember_me%5D=0&commit=Sign+in"
[...]

As you can see, the password is right there in plain text.
Is this ok? If so, how can I completely filter the password??

You can see more of this issue here: https://rails.lighthouseapp.com/projects/8994/tickets/6720

Destroying a record with habtm association using foreign keys on association table raises a exception

Hi,

I have this case:

class Profile < ActiveRecord::Base
  has_and_belongs_to_many :roles
end

class Role < ActiveRecord::Base
  has_and_belongs_to_many :profiles
end

And the association table:

class CreateProfilesRoles < ActiveRecord::Migration
  def self.up
    create_table :profiles_roles, :id => false do |t|
      t.integer :profile_id
      t.integer :role_id
    end

    add_foreign_key :profiles_roles, :profiles
    add_foreign_key :profiles_roles, :roles
  end

  def self.down
    drop_table :profiles_roles
  end
end

When I try to destroy the profile, I receive an error from postgresql due to foreign keys on join table.

The join table is cleared after destroying the record and this should be done before (see: https://github.com/rails/rails/blob/3-0-stable/activerecord/lib/active_record/associations.rb#L1716)

If I change this after_destroy to before_destroy the issue is solved but breaks 4 tests on activerecord suite (using sqlite3 adapter).

I checked this issue on 3.0.0, 3.0.7, and 3.1.0.beta1

Files from file_field coming through as Array, not File objects

Hello again,

I have a project at https://github.com/rails3book/edge-ticketee/tree/chapter_8 which has the features/creating_tickets.feature feature failing because files are not being passed correctly. You can duplicate this by running:

bundle install
bundle exec cucumber features/creating_tickets.feature:38

It will give this error:

Then I should see "speed.txt" within "#ticket .asset"
    Unable to find '#ticket .asset' (Capybara::ElementNotFound)
    ./features/step_definitions/web_steps.rb:29:in `with_scope'
    ./features/step_definitions/web_steps.rb:36:in `/^(. within ([^:]+)$/'
    features/creating_tickets.feature:45:in `Then I should see "speed.txt" within "#ticket .asset"'

If you inspect the parameters in the controller for ticket, namely the asset parameter, you'll see this:

"asset"=>["The blink tag can blink faster if you use the speed=\"hyper\" attribute."]

In previous versions of Rails, this always came through as a Tempfile object, and I think Paperclip is still expecting it to be that because it's not saving that file anywhere.

View specs fail with "method `protect_against_forgery?' not defined in #<Module:0x10a678468>"

I'm attempting to upgrade a Rails 3.0 app to 3.1 edge but all of my view specs fail within action_view/test_case.

Failure/Error: Unable to find matching line from backtrace
NameError:
  method `protect_against_forgery?' not defined in #<Module:0x10a678468>
# ruby/1.8/bundler/gems/rails-92661b0c501a/actionpack/lib/action_view/test_case.rb:132:in `remove_method'
# ruby/1.8/bundler/gems/rails-92661b0c501a/actionpack/lib/action_view/test_case.rb:132:in `say_no_to_protect_against_forgery!'
# ruby/1.8/bundler/gems/rails-92661b0c501a/actionpack/lib/action_view/test_case.rb:131:in `module_eval'
# ruby/1.8/bundler/gems/rails-92661b0c501a/actionpack/lib/action_view/test_case.rb:131:in `say_no_to_protect_against_forgery!'
# ruby/1.8/bundler/gems/rails-92661b0c501a/actionpack/lib/action_view/test_case.rb:100:in `setup_with_controller'
# ruby/1.8/gems/rspec-rails-2.5.0/lib/rspec/rails/adapters.rb:11:in `send'
# ruby/1.8/gems/rspec-rails-2.5.0/lib/rspec/rails/adapters.rb:11:in `setup'

Cannot save record whose field contains '?'

How to reproduce:

u = User.first # any model with a string field is ok, use User as example
u.name = 'a?b'
u.save

The Error:

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.reverse
from /home/jan/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-785ee65ddfc3/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:302:in `block in exec_delete'
    from /home/jan/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-785ee65ddfc3/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:302:in `gsub'
    from /home/jan/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-785ee65ddfc3/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:302:in `exec_delete'
    from /home/jan/.rvm/gems/ruby-1.9.2-p180/bundler/gems/rails-785ee65ddfc3/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:95:in `update'

Related to 00f030c6#L0R297

Rails Lighthouse down?

Hello,

I'm trying to track down a possible Rails 3 bug I'm having with sessions. The last time I had to track something down I was able to browse Lighthouse to see if an issue had been addressed.

Now it seems the Rails project on Lighthouse has been locked down.

Anyone have any info?

Thanks,

Chris

Access record information from converter (AR::Aggregation)

In the aggregation implementation, there is no way to access information about the ActiveRecord instance in the converter, and it could be realy usefull.

More info: I use RubyMoney to handle a money data in a model.

 composed_of :money,
             :converter => Proc.new { |value| value.to_money}

I want to give it a default currency depending on the last saved currency (given an update) (or in data related to the ActiveRecord instance), but I cannot access this data in the converter proc.

This could be really usefull to me, and may be others.

A possible approach is to pass the record to the proc:

             :converter => Proc.new { |value, record| value.to_money(record.currency)}

I18n.t vs rails t helper

Can I ask why is I18n.t method used in form helper ? Why is not used rails t (translate) method instead ?

Nested attributes for polymorphic models

In the case of Person has_many :phones, :as => :phoneable, this happens when I submit a nested form.

Phone(#2157249660) expected, got Array(#2151973780)

You can test it for yourself with this app: https://github.com/activestylus/nested_polymorphic_attributes_bug

On closer inspection it appears the form helpers are not rendering the nested fields correctly, particularly the name attribute:

Looking at the source I see:

<input name="person[phones][number]"...

When I'm pretty sure that should be:

<input name ="person[phones][0][number]"...

FWIW I can build nested models in the console with no problems whatsoever. And the form helpers do not suffer this problem with a regular has_many relationship.

has_one polymorphic is creating circular dependency with parent model

Use this two models:

class Item < ActiveRecord::Base
belongs_to :itemable, :polymorphic => true end

class Product < ActiveRecord::Base
has_one :item, :as => :itemable, :dependent => destroy accepts_nested_attributes_for :item end

now try to:

@Product = Product.new(params[:product]) @product.build_item(params[:item]) @product.valid?

And you will get a error lacking the "item.itemable_id"

So, build_item is defining the correct itemable_type, but are not dealing with the id... I expect it to save "course" first, get it's id and them set it on itemable_id and then save "item".

PS: I've filled the bug on lighthouse but just figured out that it has moved here, so, to let you know: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6761-has_one-polymorphic-is-creating-circular-dependency-with-parent-model

Lighthouse 5478 - Postgres and Sqlite3 no longer able to map to database views

https://rails.lighthouseapp.com/projects/8994/tickets/5478/

It doesn't look like this issue was ever actually resolved, as the patch supplied in the comments was never actually applied to the source tree. For instance,

class MyTable < ActiveRecord::Base
   set_table_name 'my_view'
end

MyTable.table_exists? # => false

This is when using PostgreSQL as a backend. I can't find any mention of pg_views anywhere in the source, so I don't think that the patch was ever applied properly.

Move from lighthouse mess

I understand the reason behind the move to github issues.

Problems in the way the transition is done remain:

  1. Lighthouse issues have not been migrated to github yet (any timeframe?)

  2. Until they are, they can't be read by mere mortals on Lighthouse anymore. There is not even a landing page letting people know where to go, what to do, etc.

  3. Guides are still referring to lighthouse (http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html and even http://edgeguides.rubyonrails.org/contributing_to_rails.html )

Thanks

Fix deprecation warnings in ActiveSupport (Related to Lighthouse #4618)

/Users/msgehard/Documents/Development/rubyDevelopment/rails_source/rails/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb:21:in `to_yaml': YAML.quick_emit is deprecated

/Users/msgehard/Documents/Development/rubyDevelopment/rails_source/rails/activesupport/lib/active_support/ordered_hash.rb:37:in `to_yaml': YAML.quick_emit is deprecated

Does anyone know what the replacement for quick_emit is?

ExecJS missing runtime message needs to be improved

Got error when trying to start WebBrick

/home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/execjs-0.3.2/lib/execjs.rb:32:in `runtime': Could not find a JavaScript runtime (ExecJS::RuntimeError)
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/execjs-0.3.2/lib/execjs.rb:44
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/coffee-script-2.2.0/lib/coffee_script.rb:1
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/coffee-script-2.2.0/lib/coffee-script.rb:1
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/actionpack-3.1.0.beta1/lib/sprockets/railtie.rb:4:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/actionpack-3.1.0.beta1/lib/sprockets/railtie.rb:4:in `using_coffee?'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/actionpack-3.1.0.beta1/lib/sprockets/railtie.rb:17
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/actionpack-3.1.0.beta1/lib/action_controller/railtie.rb:7:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/actionpack-3.1.0.beta1/lib/action_controller/railtie.rb:7
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/activerecord-3.1.0.beta1/lib/active_record/railtie.rb:9:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/activerecord-3.1.0.beta1/lib/active_record/railtie.rb:9
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/all.rb:11:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/all.rb:11
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/all.rb:5:in `each'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/all.rb:5
    from /home/mojo/Sites/hello/config/application.rb:3:in `require'
    from /home/mojo/Sites/hello/config/application.rb:3
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51:in `require'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48:in `tap'
    from /home/mojo/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48
    from script/rails:6:in `require'
    from script/rails:6


methodoverride does not appear anywhere in logs

Right now, when you issue a PUT request using the _method param method override, it's not indicated anywhere in the logs. The _method parameter is stripped from the Parameters line, and the log says it was a POST request:

Started POST "/post/1" for 127.0.0.1 at 2011-05-06 16:15:58 -0700
  Processing by PostsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"pirld4RhMa0a3LRTVKGPg+KRa8Cr3To/aeyxsr4pXRI=", "name"=>"a", "commit"=>"Save changes", "id"=>"1"}

Validations' :if blocks are run before any :on checks are made

In Rails 3, if you have both an :if block and an :on declaration on the same validation, the :if block runs before the :on declaration is checked. For example, in the following code:

validates_presence_of :blah, :on => :update, :if => lambda { |record| record.id == 4 }
the :if block is run even if the context is a create.
This seems to be due to the following code in activemodel/validations/callbacks.rb:
def before_validation(*args, &block) options = args.extract_options! if options.is_a?(Hash) && options[:on] options[:if] = Array.wrap(options[:if]) options[:if] << "self.validation_context == :#{options[:on]}" end set_callback(:validation, :before, *(args << options), &block) end,
where the check is added to the end of the options[:if] array, causing the check to run after the :if block.

Ajax request / before_filter session punting

Hello,

I hope I can explain this correctly but I ran into an issue with 3.0.7 (not sure about earlier versions) while upgrading my 2.3.8 application. I use activerecord db session storage. It took awhile to track down but I have a javascript observer in the view calling a controller method and somewhere in that transaction my session hash becomes nil. It also deletes the session from the sessions table in the db.

The controller has a before_filter that calls an authorize method in the application controller and before it reaches that method the session is punted. If I add an exception to the before_filter to ignore the method the observer is calling the session remains intact.

Here's the javascript...

<script> document.observe("dom:loaded", function() { $('time_job_type').observe('change', new Ajax.Request('/time_sheets/set_collection?job_type=' + $('time_job_type').value)); }); </script>

and here's the before_filter with the exception I had to add to get it to not punt my session...

before_filter :authorize, :except => [:set_collection]

I suspect the before_filter but If I'm making a grave organizational/programming error in how I'm implementing this I'm ready to be corrected by the experts.

Thanks,

Chris

ActiveRecord::Relation#last ignores limit

The limit option is ignored when calling #last on an ActiveRecord::Relation object:

Item.where("id <= 3").order(:id).limit(2)
# returns records #1 and #2
Item.where("id <= 3").order(:id).limit(2).last
# returns record #3, not record #2 as expected, since the limit is overridden by last
Item.where("id <= 3").order(:id).limit(2).all.last
# executing the query uses Array#last instead of ActiveRecord::Relation#last, and returns #2 as expected

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.