class Category < ActiveRecord::Base
attr_accessor :status
end
should do the trick
or you could do it longhand
def status
@status
end
def status=(val)
@status = val
end
On 12/16/05, Ross Ashley <rashley-vnDaGbr9NeIAvxtiuMwx3w@public.gmane.org>
wrote:>
> I need to add an attribute to a model but there is no need to add a
> corresponding database field. The model is a child of ActiveRecord and
> it corresponds to a table in my DB but when I add it in the usual Ruby
> way, I get a ''number of redirects exceeded'' error.
>
> Here is my code;
>
> The model;
>
> class Category < ActiveRecord::Base
> attr :status
> end
>
> The controlller;
>
> if params[:id] then @category = Category.find(params[:id])
> else @category =
Category.find_by_default_category(''1'')
> end
> @category.status = 1
>
> The view (just to access it)
>
> <% for category in @categories %>
> <%= category.status %>
> etc...
>
> So, is there a way to add an attribute to an existing table based model?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails