Note that there are some explanatory texts on larger screens.

plurals
  1. PODont understand why I'm encountering this TypeError (Can't convert nil into String)
    primarykey
    data
    text
    <p>Very simple process I'm trying to implement. On a home page or landing page I want to capture emails for an email list. If the email passes validation, it gets saved, Great! Everything works fine when there are no errors.</p> <p>When there is an error like only inputting an 'a' character as shown in the log below. Or even just an empty string I continually get the same <code>TypeError</code> (can't convert nil to String)</p> <p>Here is the log:</p> <pre><code>Started GET "/" for 127.0.0.1 at 2013-06-13 13:48:56 -0400 Connecting to database specified by database.yml Processing by HighVoltage::PagesController#show as HTML Parameters: {"id"=&gt;"home"} Rendered shared/_error_messages.html.erb (0.4ms) Rendered layouts/_visitor_form.html.erb (7.9ms) Rendered pages/home.html.erb within layouts/application (13.1ms) Completed 200 OK in 82ms (Views: 39.6ms | ActiveRecord: 1.8ms) [2013-06-13 13:48:57] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started POST "/visitors" for 127.0.0.1 at 2013-06-13 13:48:59 -0400 Processing by VisitorsController#create as HTML Parameters: {"utf8"=&gt;"✓",authenticity_token"=&gt;"esTPNzNtkmNPTe7Jh+E2aDHNrgocU5Z8g49Nj0QiOhQ=", "visitor"=&gt;{"email"=&gt;""}, "commit"=&gt;"Add to newsletter list"} (0.1ms) begin transaction Visitor Exists (0.2ms) SELECT 1 AS one FROM "visitors" WHERE LOWER("visitors"."email") = LOWER('') LIMIT 1 (0.1ms) rollback transaction Completed 500 Internal Server Error in 39ms TypeError (can't convert nil into String): app/controllers/visitors_controller.rb:12:in `create' </code></pre> <p>Here is the visitors_controller.rb</p> <pre><code> def create @visitor = Visitor.new(params[:visitor]) if @visitor.save flash[:success] = "Your email has been added!" redirect_to '/' else render '/' end end </code></pre> <p>I've also tried </p> <pre><code>@visitor = Visitor.new(:visitor =&gt; params[:visitor][:email]) </code></pre> <p>and a few other sequences with no success.</p> <p>How can I get the unsuccessful saves to gracefully show the validation errors and allow the user to resubmit.</p> <p>Here is the layout:</p> <pre><code> &lt;%= form_for Visitor.new do |f| %&gt; &lt;%= render 'shared/error_messages' %&gt; &lt;%= f.label :email %&gt; &lt;%= f.text_field :email %&gt; &lt;%= f.submit "Add to newsletter list", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; </code></pre> <p>Maybe the high_voltage gem is screwing me up. I don't have enough experience to know.</p> <p>UPDATE:</p> <pre><code>rake routes visitors POST /visitors(.:format) visitors#create home /home(.:format) pages#home root / high_voltage/pages#show {:id=&gt;"home"} page GET /pages/*id high_voltage/pages#show </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload