title: Rails: passing params from one new to create
body: <p>I have an Event controller, which I re-direct to from another controllers (Registration)
      (from Registration controller):</p>
  
  <pre><code>format.html { redirect_to new_event_path(:event_count =&gt; 15) }
  
  (Event controller)
  
  def new
      logger.info params
      @event = Event.new(:event_count =&gt; params[:event_count])
      ......
  
  def create
      @event = Event.new(params[:event])
  
  and inside views/events/new.html.erb
  &lt;%= f.hidden_field :event_count %&gt;
  </code></pre>
  
  <p>However, when I try to run this, I get the following message:</p>
  
  <pre><code>unknown attribute: event_count
  </code></pre>
  
  <p>Note that when I check out the log file, from new, I can see that the parameters hash has in it {"event_count":"15"}</p>
  
  <p>Note that event_count is not in my events table. Any suggestions?</p>
  
  <h1>More info</h1>
  
  <p>I already have event_count as a virtual attribute in my Event model:</p>
  
  <pre><code>attr_accessible :event_count
  </code></pre>
  
  <p>This is a value that is only used during the runtime, and is never stored in the DB. Initially I was using session variables pass this value, but I was wondering if there is a cleaner and safer way to get this done.</p>
  
  <h1>What worked:</h1>
  
  <p>I removed the attr_accessor :event_count form my Even model.</p>
  
  <p>In Event Controller:</p>
  
  <pre><code>def new
      @event_count = params[:event_count]
      @event = Event.new
  
  def create
      .....
      @event_count = params[:event][:event_count]
  </code></pre>
  
  <p>and in my views/event.html.erb</p>
  
  <pre><code>&lt;%= f.hidden.field :event_count, :value =&gt; @event_count %&gt;
  </code></pre>