ここにフォームがあり、orders/_form.html.erb
送信してカテゴリというテーブルに保存します
<%= simple_form_for(@category) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :name,
:label => false,
:input_html => { :class => 'text',
:style => 'float:left; width:250px' },
:placeholder => "Type of item / name of expense",
%>
<%= f.hidden_field :user_id,
:value => current_user.id %>
<%= f.button :submit,
:value => 'Add Category',
:class => 'small grey',
:style => 'margin:5px 0 0 10px' %>
</div>
<% end %>
私のcategories_controller.rbには、カテゴリを作成するための次のコードがあります:
# POST /categories
# POST /categories.json
def create
@category = current_user.categories.build(params[:category])
respond_to do |format|
if @category.save
format.html { redirect_to new_order_path }
format.json { render json: new_order_path, status: :created, location: @category }
else
format.html { render action: "new" }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
まず、フォームを送信したときにページが更新されないようにするにはどうすればよいですか? 次に、Categories ドロップダウンhttp://d.pr/gUwzにも新しいエントリを追加します (JQ を使用すると想定しています)。これを始める方法はありますか?