Friday, 15 January 2010

ruby on rails - Update status will show user name -



ruby on rails - Update status will show user name -

previously in app owner of guideline edit own guideline, able edit guideline , when has updated 'edited .... on .... date'. possible?

my update action in guidelines_controller.rb is

def update @guideline = guideline.find(params[:id]) if params[:guideline] && params[:guideline].has_key?(:user_id) params[:guideline].delete(:user_id) end respond_to |format| if @guideline.update_attributes(params[:guideline]) format.html { redirect_to @guideline, notice: 'guideline updated.' } format.json { head :no_content } else format.html { render action: "show" } format.json { render json: @guideline.errors, status: :unprocessable_entity } end end end

and edit action in same controller is

def edit @guideline = guideline.find(params[:id]) @specialties = guideline.order(:specialty).uniq.pluck(:specialty) end

user model user.rb is

attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty has_many :guidelines has_many :favourite_guidelines

guidelines model is

belongs_to :user has_many :favourite_guidelines

if want maintain history of edits, have create table (guideline_edits : guideline_id, user_id, edited_at) , can show lastly edited @ . if want track changes went each of edits, can utilize audited gem

if not want maintain history, can add together edited_by (current user), edited_at (time.now()) fields guideline , update these columns on updating guideline.

and ofcourse, in authorization rules, have allow logged-in user edit guideline.

hope helps

ruby-on-rails ruby-on-rails-3

No comments:

Post a Comment