简体   繁体   中英

Clearing text_area on edit form

As the title says, i need when a user presses "edit" button on my Ticket model, the text_area field get empty and not show any current info that it pulls from the database. How can I achieve that?

You can easily do this in the controller.
Supposing your text_field is named my_field

def edit
    @ticket.my_field=nil
end

This way, it will render empty on the view.

Probably the most expedient thing to do here is to have your controller pass @ticket with the attribute's value cleared. Something like:

class TicketsController < ApplicationController
  def edit
    @ticket = Ticket.find(params[:id])
    @ticket.note_text = ""
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM