Skip to content

Instantly share code, notes, and snippets.

@msadoon
Last active August 29, 2015 14:03
Show Gist options
  • Save msadoon/706a1b8ee7a30ed40371 to your computer and use it in GitHub Desktop.
Save msadoon/706a1b8ee7a30ed40371 to your computer and use it in GitHub Desktop.
updating one record in a db
def update
d { @help }
respond_to do |format|
if @help.update(help_params)
format.html { redirect_to @help, notice: 'Help was successfully updated.' }
format.json { render :show, status: :ok, location: @help }
#redirect_to action: "index"
else
format.html { render :edit }
format.json { render json: @help.errors, status: :unprocessable_entity }
#redirect_to action: "index"
end
end
end
<% @help = Help.find_by_id(1) %>
<%= bootstrap_form_for(@help) do |f| %>
<% if @help.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@help.errors.count, "error") %> prohibited this tax rate from being saved:</h2>
<ul>
<% @help.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :id %>
<div class="field">
<%= f.text_field :gst, label: "GST", :min => 0 %>
</div>
<div class="field">
<%= f.text_field :qst, label: "QST", :min => 0 %>
</div>
<div class="actions">
<% d { @help } %>
<%= f.submit 'Update Help', :class=>"btn btn-success navbar-btn" %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment