title: How to create a new object with Ajax request?
body: <p>For example I have my index view with all objects in database. And instead of clicking on Create button I want to get it done without refreshing the page using Ajax. How to do it? How can I change my controller for this purpose? Thanks in advance.</p>
  
  <p><strong>My controller</strong></p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
  before_filter :authorize, only: [:edit, :new, :destroy]
  
    def index
      @articles = current_user.articles
    end
  
    def show
      @article = Article.find(params[:id])
      redirect_to users_path
    end
  
    def edit
      @article = Article.find(params[:id])
    end
  
    def new
      @article = Article.new
    end
  
  
    def create
      @article = current_user.articles.build(article_params)
  
      if @article.save
        redirect_to user_articles_path(current_user)
      else
        render 'new'
      end
    end
  
  
    def update
      @article = Article.find(params[:id])
      respond_to do |format|
      if @article.update(article_params)
        format.html {redirect_to user_articles_path(current_user), notice: 'Post was successfully updated'}
        format.json { head :no_content }
      else
        format.html {render action: 'edit' }
      end
    end
   end
  
    def destroy
      @article = Article.find(params[:id])
      @article.destroy
      respond_to {|format| format.js }
    end
  
    private
  
      def article_params
        params.require(:article).permit(:title)
      end
   end
  </code></pre>