Created
August 31, 2012 01:24
-
-
Save glennmartinez/3547344 to your computer and use it in GitHub Desktop.
not getting quote.id from return ajax search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <table> | |
| <% @contractors.each do | contractor | %> | |
| <tr> | |
| <td><%= contractor.firstname %></td> | |
| <td> | |
| <%= form_tag quote_add_contractor_path, :method => 'post', :id => "contractors_search" do %> | |
| <%= hidden_field_tag :quote_id, @quote.id %> | |
| <%= hidden_field_tag :contractor_id, contractor.id %> | |
| <%= submit_tag "Add" %> | |
| <% end %> | |
| </td> | |
| </tr> | |
| <% end %> | |
| </table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $("#contractors").html("<%= escape_javascript(render :partial => "contractors") %>"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class QuotesController < ApplicationController | |
| before_filter :load_contractors | |
| before_filter :find_project, :only => [:new, :create] | |
| def index | |
| @quotes = Quote.all | |
| @quote = Quote.find(params[:quote_id]) | |
| @contractors = Contractor.search(params[:search]) | |
| end | |
| def new | |
| # @quote = Quote.new | |
| @quote = @project.quotes.build | |
| @quote.contractors.build | |
| respond_to do |format| | |
| format.html # new.html.erb | |
| format.json { render json: @quote } | |
| end | |
| end | |
| def add_contractor | |
| @quote = Quote.find(params[:quote_id]) | |
| @contractor = Contractor.find(params[:contractor_id]) | |
| @quote.contractors << @contractor | |
| if @quote.save | |
| redirect_to @quote, notice: "contractor was added" | |
| else | |
| render :show, notice: "Sorry, something went aweful" | |
| end | |
| end | |
| def get_contractor | |
| @quote = Quote.find(params[:format]) | |
| @contractors = Contractor.search(params[:search]) | |
| end | |
| def create | |
| # @quote = Quote.new(params[:quote]) | |
| @quote = @project.quotes.build(params[:quote]) | |
| respond_to do |format| | |
| if @quote.save | |
| format.html { redirect_to @quote, notice: 'Project was successfully created.' } | |
| # format.json { render json: @project, status: :created, location: @project } | |
| else | |
| format.html { render action: "new" } | |
| # format.json { render json: @project.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| def show | |
| @quote = Quote.find(params[:id]) | |
| # @contractors = Contractor.search(params[:search]) | |
| end | |
| private | |
| def load_contractors | |
| @contractors = Contractor.all | |
| end | |
| private | |
| def find_project | |
| @project = Project.find(params[:project_id]) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_tag quote_get_contractor_path(@quote), :method => 'get', :id => "contractors_search" do %> | |
| <p> | |
| <%= text_field_tag :search, params[:search] %> | |
| <%= submit_tag "Search", :name => nil %> | |
| </p> | |
| <br><br><br> | |
| <div id="contractors"><%= render 'contractors' %></div> | |
| <% end %> | |
| <script type="text/javascript"> | |
| $(function() { | |
| $("#contractors_search input").keyup(function() { | |
| $.get($("#contractors_search").attr("action"), $("#contractors_search").serialize(), null, "script"); | |
| return false; | |
| }); | |
| }); | |
| </script> | |
| </script> |
Author
Author
<%= form_tag quotes_path(@quote), :method => 'get', :id => "contractors_search" do %>
Author
<%= form_tag quote_get_contractor_path(@quote), :method => 'get', :id => "contractors_search" do %>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<%= form_tag contractor_quote_path(@quote), :method => 'get', :id => "contractors_search" do %>"