Reputation: 47
I am working on rails ..
Want to add status feature, but having problem as we need to go create and edit page of each status. Want to know how can I do on the same page without leaving the page..
Upvotes: 0
Views: 60
Reputation: 2826
I would do something like:
<%= form_for(@status, remote: true) do |f| %>
...
<% end %>
Check out the Rails guide on ajax forms.
You can render back with json like:
def create
@status = Status.find(params[:id])
respond_to do |format|
if @status.update_attributes(status_attributes)
format.html { redirect_to @status }
format.js {}
format.json { render json: @status }
else
format.html { render action: "new" }
format.json { render json: @status.errors }
end
end
I edited this to reflect updating a status.
Upvotes: 2