Ruby on Rails Sunday, November 30, 2014

Thanks, that did the trick.

I use the beta versions because on the online tutorial from Hartl that versions are mentioned and he says not to use any other version to follow the tutorial.

Roelof

Op zondag 30 november 2014 23:47:59 UTC+1 schreef Daniel Evans:
I just encountered this issue as well. This is due to an update in Arel. You should be able to solve it by adding an explicit version requirement to your Gemfile or drop back to a stable rails version as mentioned. 

gem 'arel', '6.0.0.beta2'

On Sun, Nov 30, 2014 at 2:52 PM, Colin Law <cla...@gmail.com> wrote:
On 30 November 2014 at 20:54, Roelof Wobben <rwo...@hotmail.com> wrote:
> Hello,
>
> I have this migration file :
>
> class CreateUsers < ActiveRecord::Migration
>   def change
>     create_table :users do |t|
>       t.string :name
>       t.string :email
>       t.timestamps null: false
>     end
>   end
> end
>
> but as soon as I do rake db:migrate  I see this errors appear:
>
> bundle exec rake db:migrate
> == 20141130204806 CreateUsers: migrating
> ======================================
> -- create_table(:users)
>    -> 0.0279s
> == 20141130204806 CreateUsers: migrated (0.0281s)
> =============================
> rake aborted!
> StandardError: An error has occurred, this and all later migrations
> canceled:
> wrong number of arguments (1 for
> 0)/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in

The first thing I would do is drop back to a released version of ruby
rather than a beta version.  That is 4.1.8 I think.  It may not be the
problem but I would try it first.

Also what version of rubygems are you using?
gem -v

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLspKq8RHs9LuAhrufxHPvL5Gq%2BaeAtvPW28fNkTdY0Gvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Daniel Evans

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d53ee3c8-451b-4682-9a09-1a3e59d05db9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Saturday, 29 November 2014 22:33:07 UTC-5, Eugene Gilburg wrote:

Null Objects:

A while back, Rails 4 introduced the concept of a Null Scope. Taking the form of Person.none (or some_company.people.none), it builds a Null Relation that behaves like a "real" Active Record relation, allowing scope chaining and other interface methods available from a scope (like #count), avoiding need for brittle nil checks. I'd like to discuss extending this a general concept of Null Forms in Active Record.

Let's start with the obvious issue of mapping SQL NULLs to Ruby nils. There is a conceptual mismatch here. SQL NULL means "unknown value", while Ruby nil means "no value". This manifests itself rather painfully in anything from JOIN to NOT IN (…) queries. To make things worse, saving data from a form-based request (the most common case of introducing data into Active Record in most Rails apps) will pass blank strings from an empty form. So now you have a mix of NULLs and blank strings in your database, depending on whether or not a form ever updated the record, even if it was saved without any intentional user input.

Null Form primitives:

It may be possible to design the database to simply not allow any NULL attribute values and instead default the appropriate Null Form:

  • '' for varchars
  • 0 for ints
  • [] for serialized arrays
  • {} for Hstore or other serialized hashes

Etc.

One could argue, though, that such a design introduces excessive logic and performance penalty on the database layer, and that instead, it should be Ruby which uses the Null Form object whenever the database contains a NULL value. So, for example, if I have a database record in the users table with id=1name=NULL, and I do User.find(1).name, I'd prefer to get '' instead of nil.


A billion times no. If you want the DB to return '' for string columns that didn't have a value inserted, set the column as "default '' not null". Doing otherwise means that every client program that interacts with the DB *also* needs to apply the "NULL means empty string" convention.


 

So essentially this is a question of whether Active Record type casting should cast NULL values into their Null Form object of the appropriate type, rather than nil. But I see the obvious issues with this approach as well, notably whether #attributes should return the raw nil or use the casted Null Form, especially for APIs, so perhaps manually using database default values with null: false constraints is still the best way to accomplish this.

Null Form associations:

NULL-to-nil mismatches are yet more painful when dealing with associations, like document.project.account.name. We need to do nil checks everywhere, or use try everywhere, or delegate ... allow_nil: true hacks. How much nicer would it be if there was a Null Form association? Imagine the following:

document.project_id => nil
document
.project => <#Project id=nil>
document
.project.persisted? => false
document
.project.null? => true
document
.project.account_id => nil
document
.project.account.null? => true
document
.project.account.name? => '' # (or `nil` if not also using Null Form primitives)


Similar to the Null Primitive concept, the idea is to avoid extraneous nil checks. If the context and data type is known beforehand (and it is in the case of ActiveRecord due to schema introspection, the same logic that allows Active Record to know whether an attribute should be casted to string or integer, for example), having Null Form logic would bring a lot of the benefit of types languages into Rails, while reducing (rather than increasing) the maintenance burden and logical complexity of code. In the case of associations, this information could be inferred from has_many / has_one / belongs_to definitions, and/or introspected from used foreign keys (added in Rails 4.2).

In fact, existing code (notably accepts_nested_attributes) already expects you to manually build a new child instance if it is nil and you want an inline child object form, making you write code like @user.build_profile if @user.profile.nil? .

Discussion:

Both nil primitives and nil associations can be dealt with manually, via either explicit nil checks at point of invocation, or by using the above suggestions (such as database null: false, default: '' for blank string, controller @user.build_profile if @user.profile.nil? for blank associations, etc.) But all of these approach feel tedious and brittle, and (more importantly) add unnecessary complexity to understanding and reasoning about code.

I wonder whether anyone had experience implementing some kind of programmatic Null Form behavior for either attribute primitives, associations, or both?


I've personally used some of these patterns in specific cases, and they seemed sufficiently straightforward that framework support would have made them LESS clear.

For instance, if you've got a string that shouldn't ever be nil, and you *can't* (for some reason) just declare it "default '' not null", you can do something like this:

class SomeModel < ActiveRecord::Base
  def attribute_that_cant_be_nil
    super || ''
  end
end

(similarly with setters, if writing empty strings is not desired)

If you have an association that you want to "pop" into existence when referenced, as in the user profile thing:

class User < ActiveRecord::Base
  has_one :profile

  def profile
    super || build_profile
  end
end

With this, you can happily refer to `@user.profile` and either get the existing record or a newly-instantiated one.

If you were feeling really clever, you could even override a particular accessor (as above) to return a NullAssociationObject, but there's going to be a lot of plumbing required to make that object work all the places a model normally would...

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fd05afe3-ffa5-41fd-ad63-26f51573a409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I just encountered this issue as well. This is due to an update in Arel. You should be able to solve it by adding an explicit version requirement to your Gemfile or drop back to a stable rails version as mentioned. 

gem 'arel', '6.0.0.beta2'

On Sun, Nov 30, 2014 at 2:52 PM, Colin Law <clanlaw@gmail.com> wrote:
On 30 November 2014 at 20:54, Roelof Wobben <rwobben@hotmail.com> wrote:
> Hello,
>
> I have this migration file :
>
> class CreateUsers < ActiveRecord::Migration
>   def change
>     create_table :users do |t|
>       t.string :name
>       t.string :email
>       t.timestamps null: false
>     end
>   end
> end
>
> but as soon as I do rake db:migrate  I see this errors appear:
>
> bundle exec rake db:migrate
> == 20141130204806 CreateUsers: migrating
> ======================================
> -- create_table(:users)
>    -> 0.0279s
> == 20141130204806 CreateUsers: migrated (0.0281s)
> =============================
> rake aborted!
> StandardError: An error has occurred, this and all later migrations
> canceled:
> wrong number of arguments (1 for
> 0)/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in

The first thing I would do is drop back to a released version of ruby
rather than a beta version.  That is 4.1.8 I think.  It may not be the
problem but I would try it first.

Also what version of rubygems are you using?
gem -v

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLspKq8RHs9LuAhrufxHPvL5Gq%2BaeAtvPW28fNkTdY0Gvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Daniel Evans

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAD2%3DUWVhd4XuZ8Z-MAwMdhmFqDhizx4-p%3DR7d5ztTuqpfSCDfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On 30 November 2014 at 20:54, Roelof Wobben <rwobben@hotmail.com> wrote:
> Hello,
>
> I have this migration file :
>
> class CreateUsers < ActiveRecord::Migration
> def change
> create_table :users do |t|
> t.string :name
> t.string :email
> t.timestamps null: false
> end
> end
> end
>
> but as soon as I do rake db:migrate I see this errors appear:
>
> bundle exec rake db:migrate
> == 20141130204806 CreateUsers: migrating
> ======================================
> -- create_table(:users)
> -> 0.0279s
> == 20141130204806 CreateUsers: migrated (0.0281s)
> =============================
> rake aborted!
> StandardError: An error has occurred, this and all later migrations
> canceled:
> wrong number of arguments (1 for
> 0)/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in

The first thing I would do is drop back to a released version of ruby
rather than a beta version. That is 4.1.8 I think. It may not be the
problem but I would try it first.

Also what version of rubygems are you using?
gem -v

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLspKq8RHs9LuAhrufxHPvL5Gq%2BaeAtvPW28fNkTdY0Gvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hello,

I have this migration file :

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.string :email
      t.timestamps null: false
    end
  end
end

but as soon as I do rake db:migrate  I see this errors appear:

bundle exec rake db:migrate
== 20141130204806 CreateUsers: migrating ======================================
-- create_table(:users)
   -> 0.0279s
== 20141130204806 CreateUsers: migrated (0.0281s) =============================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 0)/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `new'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `substitute_at'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97:in `block in substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each_with_index'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56:in `insert'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:521:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/counter_cache.rb:139:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:122:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `block in _create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/timestamp.rb:57:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:501:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:142:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/validations.rb:42:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `block in save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:51:in `create!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1015:in `record_version_state_after_migrating'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:985:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ArgumentError: wrong number of arguments (1 for 0)
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `new'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `substitute_at'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97:in `block in substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each_with_index'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56:in `insert'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:521:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/counter_cache.rb:139:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:122:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `block in _create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/timestamp.rb:57:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:501:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:142:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/validations.rb:42:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `block in save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:51:in `create!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1015:in `record_version_state_after_migrating'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:985:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Roelof

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/78d2641a-d048-49f9-89e3-d6c8048a06ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

For 1) 

Use enum default field in your migration for User like this 

t.column :role, :string, default: "corporate" or use 


For 2)

Roles were stored as string and your collection contains symbols . :corporate != "corporate"  

Try this 

f.input :role, as: :radio, collection: User.roles.except(:free).collect{|x| [x.to_s, x.to_s]}

On Sat, Nov 29, 2014 at 6:03 PM, Sumit Sharma <forever.sumitsharma@gmail.com> wrote:
I need to check radio button in active admin form
I've a User model and in that I've a attribute for user's role. and for the list of roles I've created a enum.

  In my model :
    enum role: [:corporate, :demo, :free]

  my new or edit form :
    form do |f|
      f.inputs "Users" do
        f.input :email
        f.input :password
        f.input :role, as: :radio, collection: User.roles.except(:free)
      end
      f.actions
   end

when I create a new user and select a role and save, then I can save the role with the user. but when I come to edit page i didn't see the related role radio button as checked.
I need to do the two things
1) on new page show first radio button as checked
2) on edit page checked the radio button of user's role

May be this very silly question, but I don't know how to do it and didn't find any solution.

Please help and Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8b1cb268-4f83-4f2b-aa5a-916a98d45532%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj_-WE%3DJOo0TFj325JCKtVc%3DaCSHt6jv%3DWm65%2B%3DEz%2BTw9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Could you show an example of what post_params contains ? 

On Sun, Nov 30, 2014 at 4:24 PM, Psycho Shine <anndrew78@gmail.com> wrote:

Hi all!

I have 3 models: user, post, comment

User has_many :posts, :comments  Post belongs_to :user, has_many :comments  Comments belongs_to :user, post

So for creating post i have action create

def create      @post = Post.new(post_params)        if @post.save        redirect_to @post      else        render 'new'      end  end

Now if following the rules of relations between Post and Comment, for creating a comment i have next action in CommentController:

def create      @post = Post.find(params[:post_id])      @comment = @post.comments.create(comment_params)      redirect_to post_path(@post)  end

My question is: How rewrite the actions if i want create post and comment from user?

if i try to create Comment from User, i create next action (don't know am i right?)

def create      @user = User.find(params[:user_id])      @post = user.posts.build(post_params)      if @post.save        flash[:success] = "Post created!"        redirect_to post_path      else        flash[:errors] = "Post not created!"        render 'new'      end  end

How create a comment from user, that will be in relations with post? i mean comment must have user_id and post_id?

tnx 4 help

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8a1c4cf8-cf08-4dad-b934-d0f27ce21684%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj__V8W3DKhSN4vKaWMJaDyzpB-Lkr1w037Ld-mrx_%2BStg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hello,

We are experts in the field of outsourcing and we all know how to run projects remotely. The team of developers encodes ripped from our office in Poznan established customers, most of which come from Scandinavia. The secret of smooth cooperation is based on well-defined project management methods and tools that have proven their effectiveness in the successful implementation of many projects.

A few of our projects:

- Teamlens.io an internal startup, SaaS application. The main objective is to assist teamlens.io communication within the company for project management - employees are required to place the daily status of the relevant projects, everyone gets a daily summary of what has happened in the company. In addition, the tool integrates with other applications that support or even support projekami management - as trello, Assembla, pivotal tracker and much more (as. For example. Bitbucket, Github). Option time tracking and the ability to provide reports to customers makes it an invaluable tool to facilitate communication and increase the transparency of the work to the client.

- Boardreport.dk - SaaS application that enables you to easily create reports for management companies. The system provides a simple interface that provides easy to collect primary data (KPIs, etc.) for specific accounting periods, allows you to quickly prepare a complete report with graphs and comments for a specific section.

- Send24.com - complete platform for shipments - prepared for the Danish client application allows you to manage your network service shipments, track their status, maintenance of wages, etc.

- Elvium.com - SaaS application facilitates the recruitment process, which takes place entirely in one place. In addition, some have been implemented sophisticated algorithms that automatically assess compliance with the requirements of the candidate's profile position to which recruitment is carried out

- Quaorganic.com - a system of online store sales combined with the tool (dedicated app for iPad) for sales representatives.

- Mypis.pl - a social networking site for the largest right-wing party in the country. In addition to the integration layer is designed to integrate social networking enthusiasts typically uodostępniając functionality, such as. Blogs, microblogs, forums, share and comment on photos.

- KlubKibicaRP (http://klubkibicarp.pl) - In group - an information portal commissioned by the Official Fan Club of Poland. The prepared before the Euro2012 championships, was to be the principal supporters of integration and the only place where you could buy presale tickets for matches representation.

- Diffstore.de - The sales platform with clothing "custom" (ie. For people with non-standard dimensions or, for example. Burqas and swimwear for Muslims) modeled on etsy.com - resellers can create their own accounts / subshops and under their clothing to sell yourself.

- Idu.edu.pl - e-diary and school management system - commissioned by several private schools in Warsaw, the system provides a complete solution to manage the students, their grades, homework, lesson plans, and payments. In addition, there are the typical type of forum modules, whether internal messaging system.

- Motorismo.pl - In group-information platform prepared for one of the largest Polish distributor of motorcycle accessories

- Gazetylokalne.pl - journalism platform prepared for the Association of Local Newspapers. The system is completely modular - each publisher can create your own page layout, customize colors and logos to better visual identification. Allows you to manage multiple independent newspapers for many regions.

More information https://prograils.com/pl5

If anyone is interested please contact me

adam.jablonka@prograils.com

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/54ff0e37-9bc9-46ae-a735-ba79a26c0875%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On 30 November 2014 at 09:56, bradford li <bradfordli@gmail.com> wrote:
> I posted a question on stackoverflow:
>
> http://stackoverflow.com/questions/27211929/adding-row-to-table-through-form
>
> I am getting an error trying to add rows to my table when I click submit on
> my form. I am not sure where I am going wrong.

The error shown is

NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/users_controller.rb:32:in `create'

That tells you that you have an object that you something like
variable[..] but the variable is nil. It tells you which line the
problem is on. You need to debug your code to find why that variable
is nil. Often the log in log/development.log can be useful. For very
simple debugging you can insert code such as
puts myvariable.inspect
in, for example, the controller, and that will show the variable in
the server terminal window.

Colin



>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/75782964-5e77-4e82-9ec9-837ac9cebaa2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv_DgNLCeAxxJN18QY1f38ka3VtxMSOubZ0D78z3jWpoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi all!

I have 3 models: user, post, comment

User has_many :posts, :comments  Post belongs_to :user, has_many :comments  Comments belongs_to :user, post

So for creating post i have action create

def create      @post = Post.new(post_params)        if @post.save        redirect_to @post      else        render 'new'      end  end

Now if following the rules of relations between Post and Comment, for creating a comment i have next action in CommentController:

def create      @post = Post.find(params[:post_id])      @comment = @post.comments.create(comment_params)      redirect_to post_path(@post)  end

My question is: How rewrite the actions if i want create post and comment from user?

if i try to create Comment from User, i create next action (don't know am i right?)

def create      @user = User.find(params[:user_id])      @post = user.posts.build(post_params)      if @post.save        flash[:success] = "Post created!"        redirect_to post_path      else        flash[:errors] = "Post not created!"        render 'new'      end  end

How create a comment from user, that will be in relations with post? i mean comment must have user_id and post_id?

tnx 4 help

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8a1c4cf8-cf08-4dad-b934-d0f27ce21684%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Are the methods end_of_decade and beginning_of decade something that the developers might find useful ?
If yes, please consider this PR.

Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eaddad0c-a3c1-4b64-a7c6-4fd14db2ccab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I posted a question on stackoverflow:

http://stackoverflow.com/questions/27211929/adding-row-to-table-through-form

I am getting an error trying to add rows to my table when I click submit on my form. I am not sure where I am going wrong.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/75782964-5e77-4e82-9ec9-837ac9cebaa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails Saturday, November 29, 2014

Null Objects:

A while back, Rails 4 introduced the concept of a Null Scope. Taking the form of Person.none (or some_company.people.none), it builds a Null Relation that behaves like a "real" Active Record relation, allowing scope chaining and other interface methods available from a scope (like #count), avoiding need for brittle nil checks. I'd like to discuss extending this a general concept of Null Forms in Active Record.

Let's start with the obvious issue of mapping SQL NULLs to Ruby nils. There is a conceptual mismatch here. SQL NULL means "unknown value", while Ruby nil means "no value". This manifests itself rather painfully in anything from JOIN to NOT IN (…) queries. To make things worse, saving data from a form-based request (the most common case of introducing data into Active Record in most Rails apps) will pass blank strings from an empty form. So now you have a mix of NULLs and blank strings in your database, depending on whether or not a form ever updated the record, even if it was saved without any intentional user input.

Null Form primitives:

It may be possible to design the database to simply not allow any NULL attribute values and instead default the appropriate Null Form:

  • '' for varchars
  • 0 for ints
  • [] for serialized arrays
  • {} for Hstore or other serialized hashes

Etc.

One could argue, though, that such a design introduces excessive logic and performance penalty on the database layer, and that instead, it should be Ruby which uses the Null Form object whenever the database contains a NULL value. So, for example, if I have a database record in the users table with id=1name=NULL, and I do User.find(1).name, I'd prefer to get '' instead of nil.

So essentially this is a question of whether Active Record type casting should cast NULL values into their Null Form object of the appropriate type, rather than nil. But I see the obvious issues with this approach as well, notably whether #attributes should return the raw nil or use the casted Null Form, especially for APIs, so perhaps manually using database default values with null: false constraints is still the best way to accomplish this.

Null Form associations:

NULL-to-nil mismatches are yet more painful when dealing with associations, like document.project.account.name. We need to do nil checks everywhere, or use try everywhere, or delegate ... allow_nil: true hacks. How much nicer would it be if there was a Null Form association? Imagine the following:

document.project_id => nil
document
.project => <#Project id=nil>
document
.project.persisted? => false
document
.project.null? => true
document
.project.account_id => nil
document
.project.account.null? => true
document
.project.account.name? => '' # (or `nil` if not also using Null Form primitives)


Similar to the Null Primitive concept, the idea is to avoid extraneous nil checks. If the context and data type is known beforehand (and it is in the case of ActiveRecord due to schema introspection, the same logic that allows Active Record to know whether an attribute should be casted to string or integer, for example), having Null Form logic would bring a lot of the benefit of types languages into Rails, while reducing (rather than increasing) the maintenance burden and logical complexity of code. In the case of associations, this information could be inferred from has_many / has_one / belongs_to definitions, and/or introspected from used foreign keys (added in Rails 4.2).

In fact, existing code (notably accepts_nested_attributes) already expects you to manually build a new child instance if it is nil and you want an inline child object form, making you write code like @user.build_profile if @user.profile.nil? .

Discussion:

Both nil primitives and nil associations can be dealt with manually, via either explicit nil checks at point of invocation, or by using the above suggestions (such as database null: false, default: '' for blank string, controller @user.build_profile if @user.profile.nil? for blank associations, etc.) But all of these approach feel tedious and brittle, and (more importantly) add unnecessary complexity to understanding and reasoning about code.

I wonder whether anyone had experience implementing some kind of programmatic Null Form behavior for either attribute primitives, associations, or both? Did you only use application-level solutions similar to above? Or did you try some kind of framework-level approach to dynamically build Null Form objects for handling database NULL values? How well did the rest of your code, as well as Rails handle it? For example, there is no way in Ruby to override the truthiness of a Null Object for `if object { a } else { b }` type comparisons, so any object other than nil would behave differently, including any custom Null Form.

Or, perhaps, there is already some literature you know, or ideas you have, about the best practices to better handle nil primitives/associations? I'd love reading about it.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82c60e70-49d9-4720-8771-e985e6a04df2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.