我在Rails中的表单上有一个可编辑的<div>
列表,如下所示:
<div id="article14" style="display: block;">Content one</div>
<div id="article15" style="display: block;">Content two</div>
<div id="article16" style="display: block;">Content three</div>
用户是否应该通过我的控制器将更改的内容更改为新的Rails记录。我已经创建了记录,我只需要应用程序来记录更改而不是原始的更改。因此,<div id="article16">Changed content</div>
中的更改应保存在下面的@edit.body
中。
def create
@doc = Doc.new(params[:doc])
respond_to do |format|
if @doc.save
#make editable version
if current_user.brand.try(:editable?)
@doc.articles.each do |article|
@edit = Edit.new
@edit.body = article.body
@edit.article_id = article.id
@edit.doc_id = @doc.id
@edit.user_id = current_user.id
@edit.save
end
end
@doc.create_activity :create, owner: current_user
format.html { redirect_to share_url(@doc.user.ftp, @doc) }
format.json { render json: @doc, status: :created, location: @doc }
else
format.html { render action: "new" }
format.json { render json: @doc.errors, status: :unprocessable_entity }
end
end
end
有什么想法吗?也许这是jQuery的一个案例?我不确定。干杯!