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:The first thing I would do is drop back to a released version of rubyOn 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
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.
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=1, name=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 / belo
ngs_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?
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.
The first thing I would do is drop back to a released version of rubyOn 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
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.
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.
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.
def change
create_table :users do |t|
t.string :name
t.string :email
end
end
end
== 20141130204806 CreateUsers: migrating ======================================
-- create_table(:users)
-> 0.0279s
== 20141130204806 CreateUsers: migrated (0.0281s) =============================
StandardError: An error has occurred, this and all later migrations canceled:
/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)
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.
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.
--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.
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.
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.
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/eaddad0c-a3c1-4b64-a7c6-4fd14db2ccab%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/75782964-5e77-4e82-9ec9-837ac9cebaa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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=1, name=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.