similar to: Default value for model var

Displaying 20 results from an estimated 3000 matches similar to: "Default value for model var"

2008 Jun 29
3
Working around/with Restful Authentication
I''m using Restful Authentication, and the code to create a user is pretty straight forward - there is a before_save action and a before_create action: before_save :encrypt_password before_create :make_activation_code But for some reason when I try to create a user programmatically in the controller like this: User.new(:email =>
2006 Feb 23
2
find_by_sql aliasing issue when accessing attributes
I was recently having problems accessing attributes in an object. Can somebody explain to me why this is, and if it is a bug? I have the following code: @archives = RapturePost.find_by_sql "select distinct date_format(rapture_posts.date_created,''%Y-%m'') date_created from rapture_posts where rapture_posts.site_id = 1 order by rapture_posts.date_created desc" I
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has tripped me up before. It wouldn''t be a big deal, but it can lead to a silent failure. I''d like to suggest that it either be made consistent or be made to fail loudly. The issue is that to do something before validating, but only when creating, you use `before_validation on: :create`,
2006 Feb 22
2
accessing an attribute within an embedded object
When I dump an instance variable to the web browser using object.inspect I get the following: This: <%= debug archive.inspect %> Yields this: #<RapturePost:0x2aaaacada118 @attributes={\"date_created\"=>\"2006-02\"}>" How do I access that date created value? Neither of the following work. The don''t give me the actual date value, only nil or
2006 Apr 21
2
Using before_create and conflicting setter method...
Hi, I am having trouble using before_create when I have an specialized setter method: before_save :set_campaign_start #----------------------------------------------------------------------- ------- def set_campaign_start self.campaign_start = Time.now end # We want the date to always start at midnight
2005 Dec 29
7
belongs_to causing NoMethodError exceptions ... ?
I''ve got a really strange problem using belongs_to. I apologize in advance for the length... this is going to take a while to explain. Basic idea: Creating a User requires that the user enter an email address and activation key that matches an existing PendingUser. After creating the user successfully, that pending user should be marked as "used". The problem: When I
2006 May 04
1
Instance or local vars for field helpers in partial template
I''m getting confused. If I have a view (.rhtml), I can use a field helper like: <%= text_field :mymodel, :attribute %> This uses the value from @mymodel.attribute Now, if I am rendering a template normally (i.e. not partial), I would expect @mymodel to be a model object defined as an instance variable in the controller. However, if I am rendering a partial template, I
2006 Jan 20
47
SQL Server datetime error
i have a problem with the datetime format of rails. i am unable to save a dataset to the db. here''s the error message -- the original error message was in german, so i translated it -- i get: DBI::DatabaseError: Execute OLE error code:80040E07 in Microsoft OLE DB Provider for SQL Server Couldn''t convert a char-Datatype to datetime HRESULT error code:0x80020009
2006 Aug 09
1
How to Disable Callbacks on a Model
Does anyone know how to disable a model''s callbacks? I have a routine that increments a page_view counter for various model objects in an after_filter in my ApplicationController. I call this: increment_page_view() Rather that checking through the trace array in each model callback for "increment_page_view" I''d rather disable the callbacks from inside
2009 Jun 11
8
before_create return value breaking object.save: rails bug?
I know that usually when people say ''i think i found a bug in rails/ruby'' they''ve done something dumb. I''m wondering if this is the case here, but this does seem like a genuine rails bug to me. In my user model i have a few different before_create callbacks. In one of them, if it happens to return false (just because the last statement in it evaluated to
2006 Jan 16
16
acts_as_authenticated current_user in a model?
What do I need to do to be able to use an acts_as_authenticated current_user in a model? Is there some sort of include or require I can do some where that would allow this? ********************************************************** Here is what I am trying to do: ********************************************************** class Setting < ActiveRecord::Base before_create :created_by_user #
2011 Oct 14
2
before_save :encrypt_password
I am having a problem finding the best way to make a "before_save :encrypt_password" conditional. I have to at times update user model attributes but each time I do this the password is reencrypted because of the above. I need to differentiate between when the user is first logging in and the password does need to be encrypted, and when they are already logged in and the
2006 Jun 18
2
Why can''t I use a session? (Symbol as array index)
Hi All I can''t for the life of me see what is wrong with this. Maybe it''s cause it''s midnight... I want to put some data in a session and I have some code like this: class ApplicationController < ActionController::Base model :mything def ApplicationController.chosen_thing session[:chosen_thing] ||= MyThing.defaultThing end end So whenever I try to
2006 Jun 08
2
how to add plugin to ActiveRecord
I''m trying to set a date field''s day to the last day of the month before I save it. I can do this successfully now using this code: class Account < ActiveRecord::Base def before_save self.exp_date = last_day_of_month(self.exp_date) end # Returns a Date object set to the last day of the current month def last_day_of_month(date = Date.today) next_month_str
2006 Jun 26
3
RJS Templates with dynamic id names
Due to the use of partials, I''m trying to dynamically generate the ids being affected in an rjs template, but I can''t seem to get the syntax to work. Basically, I need to do the equivalent of this from the .rhtml template: page.show ''mything<%= @thing.id %>'' No joy there. Apparently RJS templates don''t work with embedded ruby. So I tried:
2005 Apr 23
7
Validation question
Hi all, Is there a way to invoke validations at times other than save, create and update? I know that I can do this by writing my own validation checks using errors.add_[blah], but I''d like to leverage the existing validation code. What I have is two sets of fields in a record, set A and set B. Both sets must be validated on record create. However, the trouble is that after
2006 Jul 17
1
How to DRY up validates_presence_of
Given the case of validating the presence of an attribute and then performing other tests on said attribute, how do you go about not having to check for nil in the other tests? Example: validates_presence_of :start_date, :end_date validate :validate_start_date_before_end_date def validate_start_date_before_end_date # without this check an exception will be thrown on access to the
2006 May 09
7
going crazy!!!!!! ActiveRecord::StatementInvalid in Project
any suggestions on why I am gaining this error. ActiveRecord::StatementInvalid in ProjectsController#create Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' , , , , )'' at line 1: INSERT INTO projects (`name`, `date_created`, `quote_id`, `client_id`, `description`, `user_id`)
2006 Jul 11
18
Zip Code Ranges
Does anyone have any recommendations for working with zip code distance ranges? I need to calculate the distances between US zip codes. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060711/f133d7de/attachment-0001.html
2006 Jun 13
9
Find DB items by "title"
I''m having trouble finding then displaying all items in my "posts" table that match a certain search string. I have a from field: <%= start_form_tag :action=> "search" %> <div title="Search" id="searchform" class="form"> <h3>Search</h3> <%= error_messages_for ''post''