Rails, Is there any way in my view use link_to to grab the contents of a specific field and place it in a ruby variable?
Basically I am trying to capture the value of the form field before it is saved to the database. Then I intend to use that value in my controller to update a specific field in the database,
using @taskforms.update_attribute('notes', $notes)
I need to do this because I know of no other way to update that that does not require the full record to be validated.
The suggestion below to use @taskforms.save(false) is really not what I was looking for optimally. However it could work. However having and issue to get it to work.
What I am currently using (that works with validations)
def myupdate
@taskforms = Taskforms.find(params[:id])
respond_to do |format|
if @taskforms.update_attributes(params[:taskforms])
@taskforms.update_attribute('edited_at', Time.new )
flash[:notice] = 'Note was successfully updated.'
format.html { redirect_to(:controller => "taskforms", :action => "displayedit", :id => @taskforms.id) }
format.xml { head :ok }
else
format.html { render :action => "displayedit" }
format.xml { render :xml => @taskforms.errors, :status => :unprocessable_entity }
end开发者_运维百科
end
end
However when I try the save(false) it doesn't save and triggers validations anyway
def myupdate
@taskforms = Taskforms.find(params[:id])
if @taskforms.save(false)
@taskforms.update_attribute('edited_at', Time.new )
flash[:notice] = 'Note was successfully updated.'
format.html { redirect_to(:controller => "taskforms", :action => "displayedit", :id => @taskforms.id) }
format.xml { head :ok }
else
format.html { render :action => "displayedit" }
format.xml { render :xml => @taskforms.errors, :status => :unprocessable_entity }
end
end
I have never used Save in the past just the default respond_to do |format| so suspect my code is incorrect.
@taskforms.save(false)
will save your model without any validations if that is your main goal.
精彩评论