Reputation: 760
I am trying to work out how to achieve, in Rails 4, the modifying of some displayed data on a form page while keeping the rest of the user modified data intact.
The poster child for this is the Wordpress blog post editor. It displays a list of tags (and categories) in a post, allows the user to edit the content, and keeps that intact when adding and deleting tags.
The tags appear to be reloaded, and any changes to the post are not lost.
I'm assuming this is done through Javascript, but not sure how.
Can anyone provide an example, or point me to something that can help?
Thanks.
Upvotes: 0
Views: 772
Reputation: 2786
Let me explain the whole flow of the ajax-rails and remote=> true and you can do this with that following way and reload your modified data on the view page
first when you used the remote=> true then the form will submit or call the action which you have define in form like here is an example:
<%= form_tag({:controller => 'my', :action => 'my_data'},:id => 'filter_form', :remote => true) do %>
#code here
<%= submit_tag 'save', :name => 'commit'%>
<%end%>
now above code will go to my_data action in my controller,
here you can define the respone type with
def my_data
#actions on data here
respond_to do |format|
format.js
end
now you have to made a .js file with named as action name....
my_data.js.erb
here the whole affect of form you can write and update document element through jquery and javascript.
Upvotes: 1