Save 36% for Black Friday! Learn more

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I render a partial which contains a json object and iterate over the json object and appends it to where I want it too!! Frustration level 1000

PDG+creative asked in General

So here is the Scenario of what I am trying to do

I have a view

              = link_to admin_page_path(page), class: "edit-#{page.id}" do
                .subcategory.btn.btn-xs.btn-info{"data-subcategory" => page.id}
                  View Subcategories

Here is my javascript

:javascript
  $('.subcategory').on('click', function(e){
    e.preventDefault();

    row = $(this)
    page_id = $(this).data('subcategory');
    console.log(page_id);

    Rails.ajax({
      url: "/admin/pages/" + page_id,
      type: "get",
      dataType: "json",
      success: function(data) {
          /*render partial with data*/ 
     },
      error: function() {
        console.log('the covids')
      }
    })
  })

Here is the controller

  def show
    @page = Page.find(params[:id])
    @page_subcategories = @page.subcategories
    render json: @page_subcategories
     how can I render a partial with the @page_subcategories json response?
  end

How can I get @page_subcategories into a partial which than appends to the specific table row id

Please !

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.