title: How can I access params (or utilize a workaround) in my rails model?
body: <p>I'm trying to refactor some code out of my rails controller to my model, and I've discovered a gap in my understanding of how rails works. I'm attempted to make the 2 methods available to the Raffle class, and I'm struggling to understand how to do so. When I hit this code, the error &quot;undefined local variable or method `params' for #Raffle:0x00007f88c9af8940&quot; is returned.</p>
  <p>How can I work around params not being available to the model? Apologies if this is a beginner question- I am definitely a beginner.</p>
  <pre><code>#app/models/raffle.rb
  
  class Raffle &lt; ApplicationRecord
      has_many :tickets
      has_many :users, through: :tickets
  
      def bid_tickets(tier)
          params[:raffle][:&quot;tier&quot;].to_i #error returned here
      end
      
      def bid_total
          (bid_tickets(gold) * 3) + (bid_tickets(silver) * 2) + bid_tickets(bronze)
      end
  </code></pre>
  <pre><code>#app/views/edit.html.erb
  
  &lt;%= form_for(@raffle) do |f| %&gt;
    &lt;%=f.label :ticket, &quot;Gold&quot; %&gt;: &lt;br&gt;
    &lt;%= image_tag &quot;gold.jpg&quot;, class: &quot;small_ticket&quot; %&gt;&lt;br&gt;
    &lt;%=f.number_field :gold%&gt;&lt;br&gt;
    &lt;%=f.label :ticket, &quot;Silver&quot; %&gt;:&lt;br&gt;
    &lt;%= image_tag &quot;silver.jpg&quot;, class: &quot;small_ticket&quot; %&gt;&lt;br&gt;
    &lt;%=f.number_field :silver %&gt;&lt;br&gt;
    &lt;%=f.label :ticket, &quot;Bronze&quot; %&gt;:&lt;br&gt;
    &lt;%= image_tag &quot;bronze.jpg&quot;, class: &quot;small_ticket&quot; %&gt;&lt;br&gt;
    &lt;%=f.number_field :bronze %&gt; &lt;br&gt;&lt;br&gt;
    &lt;%= f.submit &quot;Use Tickets&quot; %&gt;
  &lt;% end %&gt;&lt;br&gt;
  </code></pre>
  <pre><code>#app/controllers/raffles_controller.rb
  
  def update
        if @raffle.enough_slots? + @raffle.current_bids &gt; @raffle.number_of_ticket_slots
                if enough_tickets? 
            redirect_to edit_raffle_path, notice: &quot;You do not have enough tickets.&quot;
          else
          redirect_to edit_raffle_path, notice: &quot;There aren't enough spots left in this raffle to handle your entry! Please use less tickets.&quot;
          end
        else @raffle.update_tickets(current_user)
          if @raffle.slots_filled?
            @raffle.select_winner
          end
         redirect_to edit_raffle_path(@raffle)
        end
      end
  </code></pre>
  <pre><code>returned parameters:
  
  {&quot;_method&quot;=&gt;&quot;patch&quot;,
   &quot;authenticity_token&quot;=&gt;&quot;xyz&quot;,
   &quot;raffle&quot;=&gt;{&quot;gold&quot;=&gt;&quot;1&quot;, &quot;silver&quot;=&gt;&quot;&quot;, &quot;bronze&quot;=&gt;&quot;&quot;},
   &quot;commit&quot;=&gt;&quot;Use Tickets&quot;,
   &quot;id&quot;=&gt;&quot;1&quot;}
  </code></pre>
  <p>EDIT:</p>
  <pre><code>#app/controllers/raffles_controller.rb (StrongParameters)
  class RafflesController &lt; ApplicationController
   private 
  
      def raffle_params
        params.require(:raffle).permit(:product_name, :product_description, 
        :product_image, :number_of_ticket_slots, :filter)
      end
  end
  </code></pre>