Hi All,
I have a very puzzling problem with a Rails 3.1.0.rc4/.rc5 app and I could be
missing something very obvious.
I have a table (workunits) with a column (worked_seconds) that I can''t
read or write. I''ve run migrations to remove and re-add it and I still
have the issue.
If I manually add a value to the column in the table using Sequel Pro, AR
returns a record that includes the correct value of the column (see below) but
referencing the column via @workunit.worked_seconds returns nil (see below).
I''d appreciate any thoughts and suggestions.
**Leigh
--------------------------------
----[schema.rb]
create_table "workunits", :force => true do |t|
t.datetime "started_on"
t.datetime "ended_on"
t.integer "user_id"
t.integer "task_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "worked_seconds"
end
----[workunit.rb]
class Workunit < ActiveRecord::Base
belongs_to :user
belongs_to :task
attr_accessor :worked_seconds
end
-----[workunits_controller.rb]
def show
@workunit = Workunit.find(params[:id])
session[:current_workunit_id] = @workunit.id
respond_to do |format|
format.html # show.html.erb
format.json { render json: @workunit }
end
end
----[show.html.erb]
<% title "Workunit for: #{@workunit.task.name}" %>
<%= @workunit.inspect %>
======> [produces:
#<Workunit
id: 6
started_on: "2011-07-24 16:00:00"
ended_on: "2011-07-24 18:59:00"
user_id: 1
task_id: 8
created_at: "2011-07-26 01:46:00"
updated_at: "2011-07-26 01:57:44"
worked_seconds: 14400>
======> ]
<hr />
<p>
<b>Started on:</b>
<%= @workunit.started_on.to_s(:long) %>
</p>
<p>
<b>Ended on:</b>
<%= @workunit.ended_on.to_s(:long) %>
</p>
<p>
<b>Worked seconds:</b>
<%= @workunit.worked_seconds.inspect %>
======> [produces: nil
======> ]
</p>
<p>
<b>User:</b>
<%= @workunit.user.email %>
</p>
<p>
<b>Task:</b>
<%= @workunit.task.name %>
</p>
<%= link_to ''Edit'', edit_workunit_path(@workunit) %> |
<%= link_to ''Back'', workunits_path %>
----[Gemfile]
source ''http://rubygems.org''
gem ''rails'', ''>= 3.1.0.rc4''
gem ''sqlite3''
gem ''sass-rails'', "~> 3.1.0.rc"
gem ''coffee-script''
gem ''uglifier''
gem ''rspec-rails''
gem ''cucumber-rails''
gem ''mysql2''
gem ''jquery-rails''
gem ''webrat'', ''>= 0.7.2''
gem ''devise''
gem ''factory_girl_rails''
group :test do
# Pretty printed test output
gem ''turn'', :require => false
gem ''database_cleaner''
end
--
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 26 July 2011 03:59, Leigh Daniels <leighdaniels42-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > I have a very puzzling problem with a Rails 3.1.0.rc4/.rc5 app and I could be missing something very obvious. > > I have a table (workunits) with a column (worked_seconds) that I can''t read or write. I''ve run migrations to remove and re-add it and I still have the issue. > > If I manually add a value to the column in the table using Sequel Pro, AR returns a record that includes the correct value of the column (see below) but referencing the column via @workunit.worked_seconds returns nil (see below). > > [...] > > class Workunit < ActiveRecord::Base > belongs_to :user > belongs_to :task > > attr_accessor :worked_secondsThat is the problem, attr_accessor creates access methods that override those that access the database columns. Remove this line (or perhaps you meant attr_accessible?). Colin -- 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 26 July 2011 03:59, Leigh Daniels <leighdaniels42-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi All, >> >> I have a very puzzling problem with a Rails 3.1.0.rc4/.rc5 app and I >could be missing something very obvious. >> >> I have a table (workunits) with a column (worked_seconds) that I can''t >read or write. I''ve run migrations to remove and re-add it and I still >have the issue. >> >> If I manually add a value to the column in the table using Sequel Pro, >AR returns a record that includes the correct value of the column (see >below) but referencing the column via @workunit.worked_seconds returns >nil (see below). >> >> [...] >> >> class Workunit < ActiveRecord::Base >> belongs_to :user >> belongs_to :task >> >> attr_accessor :worked_seconds > >That is the problem, attr_accessor creates access methods that >override those that access the database columns. Remove this line (or >perhaps you meant attr_accessible?). > >Colin >Thank you, Colin!! I was pretty sure it was a case of Rails doing what I told it to do and not what I meant for it to do. I did mean "attr_accessible". **Leigh -- 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.