ruby on rails - Rails4 method: :patch at index page using jquery/ajax -


would ask, how make like, lets says have table post , have column status (which publish or unpublish).. @ posts#index, i've button mark publish or unpublish.

<%= link_to 'publish', post, method: :patch, remote: true %> <%= link_to 'unpublish', post, method: :patch, remote: true %> 

so want update status field through ajax using method patch.. can give me idea how it?

more 1 way this. here's simple , straight forward way. in view:

<%= link_to 'publish', publish_post_path, method: :patch, remote: true %> <%= link_to 'unpublish', unpublish_post_path, method: :patch, remote: true %> 

and add them config/routes.rb. provide publish_post_path used in view , direct them publish action in posts_controller

resources :posts   member     patch :publish     patch :unpublish   end end 

and finally, add 2 actions controller:

  def publish     ...   end    def unpublish     ...   end 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -