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
end
I need to follow these steps from this code.
- Autosave periodically (possibly 1 minute)
- Give the opportunity to save a draft
- , : , , , , .
, Rails : "" post? ?
, , . , ! !