user3618619
user3618619

Reputation: 15

Updating multiple check_box_tag in show page

I am trying to update multiple check boxes in my show page . I am really stuck on how to do this and a lot of the help online has really confused me. I am still a rails noob. im using rails 4.

*Edit*

the error i currently get is Missing template lottery/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}.

Here is my controller for my page

class LotteryController < ApplicationController

  before_filter :authenticate_user, :only => [:new, :show,:update]

  def new
    @winner = Lottery.pickWinner()
  end

  def show
    @conferences = Conference.all
    #@lead = Lead.all
    @leads = Lead.new
  end

  def update
  end
end

and my show.html.erb page for this controller

     <body> 
      <%= form_tag do %>
    <% @conferences.each  do |c| %>

    <table class = 'table table-striped table-responsive table-bordered table-  condensed'>
        <h1> Conference : <%= c.name %> </h1>
        <tr>
            <td><b>First Name</b></td>  
            <td><b>Last Name</b></td>
            <td><b>Email</b></td>   
            <td><b>Department</b></td>  
            <td><b>Title</b></td>
            <td><b>Company</b></td> 
        </tr>
        <tr>
            <% @leads.get_lead_by_conference(c.id).each do |l| %>
                <td>  <%= l.lead_first_name %> </td>
                <td>  <%= l.lead_last_name  %> </td>
                <td> <%= l.email %> </td>
                <td> <%= l.department %></td>
                <td> <%= l.title %> </td> 
                <td><%=l.account_name %> </td>

            <td><label for="lead">Enable for Lottery</label><br/>
        <%= check_box_tag "leads_checkbox[]",l.id %> <%= l.lotter_flag %> 

            </td>

        </tr>
            <% end %>
    </table>    

   <% end %>
 <%= submit_tag "select Winners" %> 
  <%end %> 


</body>

Edit my get_lead_by_conference_id(conf_id ) under Lead model

def get_lead_by_conference(conf_id)
        #  get all leads that correspond with conf id
     Lead.where(:conference_id => conf_id)
end 

so what i am exactly trying to do is in my show page i have multiple tables separated by these conferences. In each conference i have a lead and i want to select a winner in each conference for a lottery. the attribute in the Leads model that is a boolean is lotter_flag. I want to update all those leads with the marked checked box after clicking the submit button. A few things that has stomped is that im updating the Leads model under a different controller. Thanks in advance and i do apologize if i have format errors.

Upvotes: 0

Views: 59

Answers (1)

Pavan
Pavan

Reputation: 33542

The problem is in your show method,you have given @lead = Lead.all and in the show.html.erb,you are using @leads which is actually given as Lead.new in the show method.It doesn't make any sense and literally you are performing each on Lead.new which is wrong.

Try changing your show method like this

def show
@conferences = Conference.all 
@leads = Lead.all
@lead = Lead.new 
end 

Note: And as per the Rails Covention,Controller classnames should be plural.In your case it should be LotteriesController not LotteryController. Although now the convention is not the issue but it is always recommended.

Update

With regarding to your error,Rails is actually looking for file called create.

You should be changing the form_tag in your show.html.erb like this

<%= form_tag :action => "create" do %>

and also you should be having a create method in your controller.

Upvotes: 1

Related Questions