Roman Catz
2010-Jun-08 07:37 UTC
[Rails Heroku] Problem with saving object (on heroku hosting)
Hi All,
I have some strange problem which appears only on heroku hosting 2.3.5
default stack (not on my local computer)
I have some models. Here they are:
class Contact < ActiveRecord::Base
belongs_to :user
belongs_to :type, :class_name => "ContactType", :foreign_key
=>
"type_id"
validates_presence_of :name, :on => :create, :message =>
"can''t be
blank"
validates_presence_of :type, :on => :create, :message =>
"can''t be
blank"
validates_presence_of :number, :on => :create, :message =>
"can''t be
blank"
end
class ContactType < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
end
migration:
create_table :contacts, :force => true do |t|
t.integer :user_id
t.integer :type_id
t.string :name
t.string :number
t.timestamps
end
add_index :contacts, :user_id
create_table :contact_types, :force => true do |t|
t.string :name
t.timestamps
end
end
And a simple form:
<% form_for(@contact) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :type_id %>
<%= f.collection_select(:type_id, @contact_types, :id, :name) %>
</p>
<p>
<%= f.label :number %>
<%= f.text_field :number %>
</p>
<p>
<%= f.submit ''Create'' %>
</p>
<% end %>
If i''m trying to save model and I get
There were problems with the following fields:
Contact can''t be blank
What does it mean {model name} can''t be blank?
When I try it local all save well.
Great Thanks.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jun-08 08:10 UTC
Re: [Rails Heroku] Problem with saving object (on heroku hosting)
On 8 Jun 2010, at 08:37, Roman Catz <truschev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > I have some strange problem which appears only on heroku hosting 2.3.5 > default stack (not on my local computer) > I have some models. Here they are: > > class Contact < ActiveRecord::Base > belongs_to :user > belongs_to :type, :class_name => "ContactType", :foreign_key => > "type_id" >Your problem may lie here - the type attribute (if present) is used for single table inheritance. Obviously this is adding a type method rather than an attribute but I would definitely try changing that association name. Fred> validates_presence_of :name, :on => :create, :message => "can''t be > blank" > validates_presence_of :type, :on => :create, :message => "can''t be > blank" > validates_presence_of :number, :on => :create, :message => "can''t be > blank" > end > > class ContactType < ActiveRecord::Base > validates_presence_of :name > validates_uniqueness_of :name > end > > migration: > create_table :contacts, :force => true do |t| > t.integer :user_id > t.integer :type_id > t.string :name > t.string :number > > t.timestamps > end > add_index :contacts, :user_id > > > create_table :contact_types, :force => true do |t| > t.string :name > > t.timestamps > end > end > > And a simple form: > <% form_for(@contact) do |f| %> > <%= f.error_messages %> > <p> > <%= f.label :name %> > <%= f.text_field :name %> > </p> > > <p> > <%= f.label :type_id %> > <%= f.collection_select(:type_id, @contact_types, :id, :name) %> > </p> > > <p> > <%= f.label :number %> > <%= f.text_field :number %> > </p> > <p> > <%= f.submit ''Create'' %> > </p> > <% end %> > > If i''m trying to save model and I get > There were problems with the following fields: > Contact can''t be blank > > What does it mean {model name} can''t be blank? > When I try it local all save well. > > Great Thanks. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Roman Catz
2010-Jun-08 09:59 UTC
Re: [Rails Heroku] Problem with saving object (on heroku hosting)
Thanks Frederick, but I still do not understand what''s going on here.
I changed this line to belongs_to :contact_type ..
The result is the same.
Controller was generated as standart scaffold.
def create
@contact = Contact.new(params[:contact].merge(:user =>
current_user))
respond_to do |format|
if(@contact.save)
...
Contact can''t be blank
Do you know when this validation should appear?
>
> Your problem may lie here - the type attribute (if present) is used for
single table inheritance. Obviously this is adding a type method rather than an
attribute but I would definitely try changing that association name.
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 10:59 am, Roman Catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Frederick, but I still do not understand what''s going on here. > > I changed this line to belongs_to :contact_type .. > The result is the same.Did you also change the validates_presence_of :type ? Fred> > Controller was generated as standart scaffold. > def create > @contact = Contact.new(params[:contact].merge(:user => > current_user)) > respond_to do |format| > if(@contact.save) > ... > > Contact can''t be blank > Do you know when this validation should appear? > > > > > > > Your problem may lie here - the type attribute (if present) is used for single table inheritance. Obviously this is adding a type method rather than an attribute but I would definitely try changing that association name.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes of course, currently it looks like
validates_presence_of :contact_type_id
validates_associated :contact_type
I insert some debug on the view and get something: please look into
it :)
<% form_for(@contact) do |f| %>
<%= debug(@contact) %>
The difference here is under
changed_attributes:
name:
contact_type_id:
number:
contact:
what is attribyte attribute: :contact ?
result:
heroku:
--- &id002 !ruby/object:Contact
attributes:
name: "44"
updated_at:
contact_type_id: "1"
number: rrr
user_id:
created_at:
attributes_cache: {}
changed_attributes:
name:
contact_type_id:
number:
contact:
contact_type: &id001 !ruby/object:ContactType
attributes:
name: sms
updated_at: 2010-06-08 10:57:27.197988
id: "1"
created_at: 2010-06-08 10:57:27.197988
attributes_cache: {}
errors: !ruby/object:ActiveRecord::Errors
base: *id001
errors: !map:ActiveSupport::OrderedHash {}
errors: !ruby/object:ActiveRecord::Errors
base: *id002
errors: !map:ActiveSupport::OrderedHash
contact:
- !ruby/object:ActiveRecord::Error
attribute: :contact
base: *id002
message: :blank
options: {}
type: :blank
new_record: true
user:
local:
--- &id002 !ruby/object:Contact
attributes:
number: ""
name: "444"
created_at:
contact_type_id: "1"
updated_at:
user_id:
attributes_cache: {}
changed_attributes:
name:
number:
contact_type_id:
contact_type: &id001 !ruby/object:ContactType
attributes:
name: sms
created_at: 2010-06-08 11:02:03
updated_at: 2010-06-08 11:02:03
id: "1"
attributes_cache: {}
errors: !ruby/object:ActiveRecord::Errors
base: *id001
errors: !map:ActiveSupport::OrderedHash {}
errors: !ruby/object:ActiveRecord::Errors
base: *id002
errors: !map:ActiveSupport::OrderedHash
number:
- !ruby/object:ActiveRecord::Error
attribute: :number
base: *id002
message: can''t be blank
options: {}
type: :blank
new_record: true
user:
On Jun 8, 2:54 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Jun 8, 10:59 am, Roman Catz
<trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Thanks Frederick, but I still do not understand what''s going
on here.
>
> > I changed this line to belongs_to :contact_type ..
> > The result is the same.
>
> Did you also change the validates_presence_of :type ?
>
> Fred
>
>
>
>
>
> > Controller was generated as standart scaffold.
> > def create
> > @contact = Contact.new(params[:contact].merge(:user =>
> > current_user))
> > respond_to do |format|
> > if(@contact.save)
> > ...
>
> > Contact can''t be blank
> > Do you know when this validation should appear?
>
> > > Your problem may lie here - the type attribute (if present) is
used for single table inheritance. Obviously this is adding a type method rather
than an attribute but I would definitely try changing that association name.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Here is some additional notes: If anybody know please explain: class Contact < ActiveRecord::Base belongs_to :user belongs_to :contact_type, :class_name => "ContactType", :foreign_key => "contact_type_id" has_many :request_contacts, :dependent => :destroy has_many :requests, :through => :request_properties validates_presence_of :name, :on => :create, :message => "can''t be blank" validates_presence_of :type, :on => :create, :message => "can''t be blank" validates_presence_of :number, :on => :create, :message => "can''t be blank" validates_presence_of :contact_type_id validates_associated :contact_type end Full model class If I run script/console on heroku and localhost and make some commands: @c = Contact.new @c.methods.grep(/cont/).sort on heroku => ["autosave_associated_records_for_contact", "autosave_associated_records_for_contact_type", "autosave_associated_records_for_request_contacts", "build_contact", "build_contact_type", "contact", "contact=", "contact_type", "contact_type=", "contact_type_id", "contact_type_id=", "contact_type_id?", "create_contact", "create_contact_type", "has_many_dependent_destroy_for_request_contacts", "loaded_contact?", "loaded_contact_type?", "request_contact_ids", "request_contact_ids=", "request_contacts", "request_contacts=", "set_contact_target", "set_contact_type_target", "validate_associated_records_for_request_contacts"] localhost => ["autosave_associated_records_for_contact_type", "autosave_associated_records_for_request_contacts", "build_contact_type", "contact_type", "contact_type=", "create_contact_type", "has_many_dependent_destroy_for_request_contacts", "loaded_contact_type?", "request_contact_ids", "request_contact_ids=", "request_contacts", "request_contacts=", "set_contact_type_target", "validate_associated_records_for_request_contacts"] There are different numbers of methods. Why? What are the methods contact and contact= for Contact class? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 1:37 pm, Roman Catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > There are different numbers of methods. Why? What are the methods > contact and contact= for Contact class?Are you re-opening the Contact class anywhere? Is the difference local versus heroku or development versus production mode (in production mode all your source gets loaded ahead of time which can sometimes pull in files you wouldn''t normally have loaded) Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Definitely not. The project is the same. I''m just git push it. o.k i''ll dig into prod vs dev mode and try to see the difference. Anyway thanks a lot for your attention. On 6/8/10, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jun 8, 1:37 pm, Roman Catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> There are different numbers of methods. Why? What are the methods >> contact and contact= for Contact class? > > Are you re-opening the Contact class anywhere? Is the difference local > versus heroku or development versus production mode (in production > mode all your source gets loaded ahead of time which can sometimes > pull in files you wouldn''t normally have loaded) > > Fred > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick thanks It was my mistake. Reopen for Contact was in my project. I added an error model and forgot. Following code was there request_contact.rb file class Contact < ActiveRecord::Base belongs_to :request belongs_to :contact .. Interesting moment here is that this reopening doesn''t appear locally. That is :contact added like a method. I guess it is difference in prod and dev modes? On 6/8/10, catz <truschev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Definitely not. The project is the same. I''m just git push it. o.k > i''ll dig into prod vs dev mode and try to see the difference. Anyway > thanks a lot for your attention. > > On 6/8/10, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On Jun 8, 1:37 pm, Roman Catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> There are different numbers of methods. Why? What are the methods >>> contact and contact= for Contact class? >> >> Are you re-opening the Contact class anywhere? Is the difference local >> versus heroku or development versus production mode (in production >> mode all your source gets loaded ahead of time which can sometimes >> pull in files you wouldn''t normally have loaded) >> >> Fred >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 6:04 pm, catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Frederick thanks It was my mistake. Reopen for Contact was in my project. > > I added an error model and forgot. Following code was there > request_contact.rb file > class Contact < ActiveRecord::Base > belongs_to :request > belongs_to :contact > .. > > Interesting moment here is that this reopening doesn''t appear locally. > That is :contact added like a method. I guess it is difference in prod > and dev modes?It''s because in production rails reads all of your app classes ahead of time whereas in development request_contact.rb wouldn''t be read until it was needed (which may well be never if that''s an obsolete piece of code) Fred> > On 6/8/10, catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Definitely not. The project is the same. I''m just git push it. o.k > > i''ll dig into prod vs dev mode and try to see the difference. Anyway > > thanks a lot for your attention. > > > On 6/8/10, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> On Jun 8, 1:37 pm, Roman Catz <trusc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> There are different numbers of methods. Why? What are the methods > >>> contact and contact= for Contact class? > > >> Are you re-opening the Contact class anywhere? Is the difference local > >> versus heroku or development versus production mode (in production > >> mode all your source gets loaded ahead of time which can sometimes > >> pull in files you wouldn''t normally have loaded) > > >> Fred > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Ruby on Rails: Talk" group. > >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. > >> To unsubscribe from this group, send email to > >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> For more options, visit this group at > >>http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.