How to render a #new view in a popup model. Ruby on Rails












0














I currently have a simple job board created in Ruby on Rails. Jobs can be created, viewed, edited, and deleted. As of right now, users can click on a job title and renders the #show view with details about the listing. From there, a user can click an apply button, which renders a form.



I am to remove the show view, and have the listings with all of their details displayed on the #index of the job_listing controller. There will be an apply button to each of the listings. This apply button is to popup a model with the application form (#new action in the leads_controller). Once the form is submitted, the popup model is to close and display the job listings again. The link is not to change and the browser is not to refresh.



I know I need to to implement AJAX requests for the data and jQuery to open and close the popup model. What I do not know is how request and display the application form.



Here is my lead_controller(lead meaning application)



class LeadsController < ApplicationController
include LeadsHelper

def new
@lead = Lead.new
end

def create
@admins = User.where('new_lead_notifications = true')
@job_listing = JobListing.find(params[:job_listing_id])
@lead = Lead.new(lead_params)
@lead.job_listing_id = params[:job_listing_id]

if @lead.save
send_leads_to_admins(@admins, @job_listing, @lead)
send_lead_conformation(@lead, @job_listing)
redirect_to thank_you_path
else
puts @lead.errors.inspect
render :new
end
end

private

def lead_params
params.require(:lead).permit(:first_name, :last_name, :email, :file)
end
end


Here is my job_listing index where the link to apply should be.



<section class="section">
<div class="container">
<% @job_listings.each do |listing| %>
<div class="card">
<div class="card-content">
<div><%= listing.title %></div>
<%# <%= link_to "Apply", new_job_listing_lead_path(listing), remote: true, class: "button is-info is-small" %> %>
</div>
</div>
<% end %>
</div>
</section>









share|improve this question





























    0














    I currently have a simple job board created in Ruby on Rails. Jobs can be created, viewed, edited, and deleted. As of right now, users can click on a job title and renders the #show view with details about the listing. From there, a user can click an apply button, which renders a form.



    I am to remove the show view, and have the listings with all of their details displayed on the #index of the job_listing controller. There will be an apply button to each of the listings. This apply button is to popup a model with the application form (#new action in the leads_controller). Once the form is submitted, the popup model is to close and display the job listings again. The link is not to change and the browser is not to refresh.



    I know I need to to implement AJAX requests for the data and jQuery to open and close the popup model. What I do not know is how request and display the application form.



    Here is my lead_controller(lead meaning application)



    class LeadsController < ApplicationController
    include LeadsHelper

    def new
    @lead = Lead.new
    end

    def create
    @admins = User.where('new_lead_notifications = true')
    @job_listing = JobListing.find(params[:job_listing_id])
    @lead = Lead.new(lead_params)
    @lead.job_listing_id = params[:job_listing_id]

    if @lead.save
    send_leads_to_admins(@admins, @job_listing, @lead)
    send_lead_conformation(@lead, @job_listing)
    redirect_to thank_you_path
    else
    puts @lead.errors.inspect
    render :new
    end
    end

    private

    def lead_params
    params.require(:lead).permit(:first_name, :last_name, :email, :file)
    end
    end


    Here is my job_listing index where the link to apply should be.



    <section class="section">
    <div class="container">
    <% @job_listings.each do |listing| %>
    <div class="card">
    <div class="card-content">
    <div><%= listing.title %></div>
    <%# <%= link_to "Apply", new_job_listing_lead_path(listing), remote: true, class: "button is-info is-small" %> %>
    </div>
    </div>
    <% end %>
    </div>
    </section>









    share|improve this question



























      0












      0








      0







      I currently have a simple job board created in Ruby on Rails. Jobs can be created, viewed, edited, and deleted. As of right now, users can click on a job title and renders the #show view with details about the listing. From there, a user can click an apply button, which renders a form.



      I am to remove the show view, and have the listings with all of their details displayed on the #index of the job_listing controller. There will be an apply button to each of the listings. This apply button is to popup a model with the application form (#new action in the leads_controller). Once the form is submitted, the popup model is to close and display the job listings again. The link is not to change and the browser is not to refresh.



      I know I need to to implement AJAX requests for the data and jQuery to open and close the popup model. What I do not know is how request and display the application form.



      Here is my lead_controller(lead meaning application)



      class LeadsController < ApplicationController
      include LeadsHelper

      def new
      @lead = Lead.new
      end

      def create
      @admins = User.where('new_lead_notifications = true')
      @job_listing = JobListing.find(params[:job_listing_id])
      @lead = Lead.new(lead_params)
      @lead.job_listing_id = params[:job_listing_id]

      if @lead.save
      send_leads_to_admins(@admins, @job_listing, @lead)
      send_lead_conformation(@lead, @job_listing)
      redirect_to thank_you_path
      else
      puts @lead.errors.inspect
      render :new
      end
      end

      private

      def lead_params
      params.require(:lead).permit(:first_name, :last_name, :email, :file)
      end
      end


      Here is my job_listing index where the link to apply should be.



      <section class="section">
      <div class="container">
      <% @job_listings.each do |listing| %>
      <div class="card">
      <div class="card-content">
      <div><%= listing.title %></div>
      <%# <%= link_to "Apply", new_job_listing_lead_path(listing), remote: true, class: "button is-info is-small" %> %>
      </div>
      </div>
      <% end %>
      </div>
      </section>









      share|improve this question















      I currently have a simple job board created in Ruby on Rails. Jobs can be created, viewed, edited, and deleted. As of right now, users can click on a job title and renders the #show view with details about the listing. From there, a user can click an apply button, which renders a form.



      I am to remove the show view, and have the listings with all of their details displayed on the #index of the job_listing controller. There will be an apply button to each of the listings. This apply button is to popup a model with the application form (#new action in the leads_controller). Once the form is submitted, the popup model is to close and display the job listings again. The link is not to change and the browser is not to refresh.



      I know I need to to implement AJAX requests for the data and jQuery to open and close the popup model. What I do not know is how request and display the application form.



      Here is my lead_controller(lead meaning application)



      class LeadsController < ApplicationController
      include LeadsHelper

      def new
      @lead = Lead.new
      end

      def create
      @admins = User.where('new_lead_notifications = true')
      @job_listing = JobListing.find(params[:job_listing_id])
      @lead = Lead.new(lead_params)
      @lead.job_listing_id = params[:job_listing_id]

      if @lead.save
      send_leads_to_admins(@admins, @job_listing, @lead)
      send_lead_conformation(@lead, @job_listing)
      redirect_to thank_you_path
      else
      puts @lead.errors.inspect
      render :new
      end
      end

      private

      def lead_params
      params.require(:lead).permit(:first_name, :last_name, :email, :file)
      end
      end


      Here is my job_listing index where the link to apply should be.



      <section class="section">
      <div class="container">
      <% @job_listings.each do |listing| %>
      <div class="card">
      <div class="card-content">
      <div><%= listing.title %></div>
      <%# <%= link_to "Apply", new_job_listing_lead_path(listing), remote: true, class: "button is-info is-small" %> %>
      </div>
      </div>
      <% end %>
      </div>
      </section>






      jquery ruby-on-rails ruby ajax






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 23:00







      Steven Heffner

















      asked Nov 23 '18 at 22:36









      Steven HeffnerSteven Heffner

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The answer was to respond with js in my controller. The js.erb file then ran some jQuery to fill the div.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453565%2fhow-to-render-a-new-view-in-a-popup-model-ruby-on-rails%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The answer was to respond with js in my controller. The js.erb file then ran some jQuery to fill the div.






            share|improve this answer


























              0














              The answer was to respond with js in my controller. The js.erb file then ran some jQuery to fill the div.






              share|improve this answer
























                0












                0








                0






                The answer was to respond with js in my controller. The js.erb file then ran some jQuery to fill the div.






                share|improve this answer












                The answer was to respond with js in my controller. The js.erb file then ran some jQuery to fill the div.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 20 '18 at 21:26









                Steven HeffnerSteven Heffner

                62




                62






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453565%2fhow-to-render-a-new-view-in-a-popup-model-ruby-on-rails%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks