What is a RESTful way to save message projects?

I have a message controller on a small test website that I am doing. I want the "save draft" / combo -auto-save function to be created on the site, as there will be long messages on the site that users may want to leave and return to completion. However, I have never created an autosave / save function in a Rails application before (or in any application). What is a good, RESTful way to do this?

Here is my current controller action:

posts_controller.rb

 def create

 @post = params[:post]
 if @post.save
     flash.now[:success] = "Post created!"
 else 
     render_errors_now(@post) 
 end
     respond_to do |format|
           format.html {redirect_to Discussion.find(session[:discussion_id])}
           format.js
     end
 end

As you can see, users are sent remotely.

Here is the current post.rb model:

 attr_accessible :content, :title
 validates :title, :presence => true 
 validate :title_character_length

 validates :content, :length => { :maximum => 10000 }
 validates :user_id, :presence => true
 validates :discussion_id, :presence => true
 belongs_to :user
 belongs_to :discussion
 default_scope :order => 'posts.created_at ASC'

 def title_character_length
    #some code that checks length
 end

I need to follow these steps from this code.

  • Autosave periodically (possibly 1 minute)
  • Give the opportunity to save a draft
  • , : , , , , .

, Rails : "" post? ?

, , . , ! !

+5
1

:

application.js

$(document).ready(function() {
  setInterval(function() {
    $('form[data-remote]').submit();
  }, 1000*60); // 1000ms * 60s = 1m
});

update.js.erb (, "" ).

, PostDraft. PostDraft, , "" - , Post PostDraft. , PostDraft. , Post "" .

+3

All Articles