フォームにチェックボックスがある記事のリストがあります。チェックボックスをオンにすると、選択した記事の本文がいずれかのx
テキスト領域にコピーされます。
ユーザーがテキスト領域の記事の本文に変更を加えたい場合、その変更をコントローラーを介して新しい Rails モデル ( と呼ばれるEdit
) に送信する必要があります。
すでに作成中のレコードがあります。変更を新しいEdit
レコードに記録するアプリケーションが必要なだけです。関連するコントローラーコードは次のとおりです。
新着
def new
@template = Template.find(params[:template])
@article_count = @template.pages-1
@doc = Doc.new
@doc.template_id = @template.id
@doc.user_id = current_user.id
@articles = current_user.brand.articles
respond_to do |format|
format.html
format.json { render json: @doc }
end
end
作成
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.name = article.name
@edit.video = article.video
#something here to get the bodies of the text areas
@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
ビュー内のテキスト領域を作成するコードは次のとおりです。
<% @article_count.times do |article| %>
<div id="edit<%= article %>" class="tab-pane <%= "active" if article == 0 %>">
<%= text_area_tag("edit[#{article}][body]") %>
</div>
<% end %>
記事ごとにレコードが作成されるのですが、テキストエリアから編集内容を保存できないようです。一種の入れ子状の配置です。どんな助けでも大歓迎です。乾杯!