Hey All, I''ve been having a slight problem updating attributes for a row that matches something other than it''s ID...For ex: My table that has 3 rows..ColumnID, ColumnTitle, and ColumnDescription. I want to update a row in that table WHERE CoumnTitle = @myvar....But whenever i run update_attrbutes[:mytable] it''s looking for an id for the record when i need to to look for the title...is there a way to override that? Any help is much appreciated! -- Posted via http://www.ruby-forum.com/.
Hey Adam. Would you send the code of your method along? That will make it easier to help. THanks Clint> > I''ve been having a slight problem updating attributes for a row that > matches something other than it''s ID...For ex: > > My table that has 3 rows..ColumnID, ColumnTitle, and ColumnDescription. > I want to update a row in that table WHERE CoumnTitle = @myvar....But > whenever i run update_attrbutes[:mytable] it''s looking for an id for the > record when i need to to look for the title...is there a way to override > that? > > Any help is much appreciated! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Clint Pidlubny wrote:> Hey Adam. Would you send the code of your method along? That will make > it easier to help. > > THanks > ClintSure....Something like this: The view is just a form with the 3 rows (ColumnID, ColumnTitle, and ColumnDescription), I specify the value for ColumnID in a hidden field (i get the value from the URL). Controller is a basic update method: #controller def save_form @column = Columns.find_by_ColumnID(params[:id]) if @column.update_attributes(params[:column]) flash[:notice] = ''Column was successfully updated.'' redirect_to :action => ''show'', :id => @column else render :action => ''edit'' end end When it executes save_form is notifies me there is no id column in UPDATE...WHERE id = NULL, but i want it to update where ColumnID = hidden ColumnID value from the form. It''s pretty basic, if i could only specify the update code it would be simple. Instead of it running UPDATE Table SET ColumnTitle = ColumnTitle WHERE id = NULL It needs to run: UPDATE Table SET ColumnTitle = ColumnTitle WHERE ColumnID = ColumnID -- Posted via http://www.ruby-forum.com/.