Rails AJAX - getting a dropdown selection to populate a table

后端 未结 3 699
醉话见心
醉话见心 2020-12-17 07:38

I\'m trying to get a selection from a dropdown to populate a table in the same page, using AJAX so that changes appear without a page refresh. I\'ve got as far as working ou

相关标签:
3条回答
  • 2020-12-17 07:44

    In js(RJS) file you need to call partial HTML file and this file have tables That you shown here in your question.

    I hope this helps you.

    Thanks.

    0 讨论(0)
  • 2020-12-17 07:49

    Create one partial _project.html.erb and render this partial in index page. <%= render @projects %> On change of project just render partial with project object and update page using rjs.

    0 讨论(0)
  • 2020-12-17 07:53

    Assume you're using jquery

    <%= collection_select :project, :id, Project.all, :id, :name, {}, {:onchange => '$.get("/populate_projects")'} %>
    

    then in your controller

    def populate_projects
      @project = Project.find(params[:id])
      respond_to do |format|
        ...
        format.js { render 'populate_projects', :formats => [:js] }
        ...
      end
    end
    

    finally, create populate_projects.js.erb and write any change table content script. @project is available in that script.

    0 讨论(0)
提交回复
热议问题