0

I'm currently building a data generator. First I want to implement is PESEL (kind of personal ID in Poland based on birth date) generator - I want to enter in form a temporary data with start and end birth date interval - I don't want to store it in database (or I should I do it?) Here is my pesel controller:

  def new
    @pesel = Array.new
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @pesel }
    end
  end

but I've got an "undefined method `model_name' for NilClass:Class" error - is it a good way anyway of solvint this case? I read somewhere that using temporary variables is not with 'The Ruby Way' - if my solution is wrong, please suggest the correct one. (e.g pass this vars through cookies? hash? helper method?)

here is the stacktrace(I think):

Started GET "/pesel" for 127.0.0.1 at 2011-12-05 16:18:20 +0100
  Processing by PeselController#new as HTML
Rendered pesel/new.html.erb within layouts/application (1513.9ms)
Completed 500 Internal Server Error in 1793ms

ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
    1: <%= simple_form_for @pesel do |f| %>
    2:   <%= f.input :date_of_birth, :as => :date, :start_year => Date.today.year - 90,
    3:                                 :end_year => Date.today.year - 12, :discard_day => true,
    4:                                 :order => [:month, :year] %>
  app/views/pesel/new.html.erb:1:in `_app_views_pesel_new_html_erb__708648673_90148530'
  app/controllers/pesel_controller.rb:7:in `new'

Rendered /home/ofca/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.6ms)
Rendered /home/ofca/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (4.0ms)
Rendered /home/ofca/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (17.6ms)
2
  • 1
    You'll need to give us a bit more about this error. Can you give us the full stacktrace? This usually tells us which line of code is actually breaking - which helps a lot. Also - it's telling you that there's a nil somewhere important. Somewhere that there shouldn't be a nil. Have a think about what might be causing this. Commented Dec 5, 2011 at 12:13
  • 1
    Check ruby-doc.org/core-1.9.2/Struct.html it can simplify building a model Commented Dec 5, 2011 at 15:43

1 Answer 1

1

form_for assumes certain properties exist for the object you pass it, such as model_name.

  1. Instead of using form_for @pesel, just use form_tag and the related _tag methods.
  2. Use a Pesel model. Models are not tables, and your model doesn't have to write anything to the database. Just don't inherit from ActiveRecord, but do provide a model_name and any other fields the form_for helper expects.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.