Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:30:24+00:00 2026-05-31T21:30:24+00:00

I am using ruby 1.9.2 and sinatra 1.3.2, Datamapper I get error: can’t convert

  • 0

I am using ruby 1.9.2 and sinatra 1.3.2, Datamapper
I get error: “can’t convert nil into Hash”

in /new_record i have a form, and when submitting the form (with some blank fields) instead of getting validation messages i get this error!

here post ‘/new_record’ – because I populating this form with some values of previous form

post '/new_record' do
        @projects = Project.all
        @date = DateTime.parse(params[:report][:date])
        erb :new_record
      end

      post '/create_record' do
        @user = User.get(current_user.id)
        if @user.records.create(params[:record])
          flash(:notice => "Report created successfully!")
          redirect "/"
    else
      @projects = Project.all
      @date = DateTime.parse(params[:report][:date])
      erb :new_record
    end

I can’t guess why because similar form works well:

  get '/new' do
    #session[:user_id] = nil
    title "Create new account"
    erb :new_user
  end

  post '/create' do
   @user = User.new(params[:user])
   if @user.save
     session[:user_id] = nil
     redirect  "/"
   else
     erb :new_user
   end
  end

I think it is something with @user.records.create(params[:record]) with create method, that it tries to build hash, but why if it can’t build a hash just don’t throw error that it couldn’t save (build) @user.records dependency ?
Is there any way to work around this? Because I would like to build record using relationship.
Thanks in advice!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:30:26+00:00Added an answer on May 31, 2026 at 9:30 pm

    DataMapper is not throwing an error that it couldn’t save because it detects a problem even before it tries to save the record. (Also notice that, by default, DataMapper doesn’t throw exceptions anyway — you have to enable it.)

    create takes a hash with the values you want to set as input. So, according to the mesasge you are reporting, apparently a nil was passed to it — and it’s complaining that it can’t convert a nil to a Hash.

    Try something like this:

    @user.records.create({:column => params[:record]})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple budget app using Sinatra and DataMapper in Ruby.
Using Sinatra in Ruby you can set the server's settings by doing: set :myvariable,
I'm working on a ruby project using Sinatra as a framework and have a
I have a basic Ruby app that I am building with Sinatra, Datamapper and
I have developed a web service(using ruby/sinatra/sqs) which runs on Linux Red Hat. I
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application
I'm building a small Ruby application using DataMapper and Sinatra, and I'm trying to
I have a Ruby/Sinatra application deployed on Heroku and I am using the IndexTank
Possible Duplicate: Error loading Active Record gem with sinatra app using RVM I have
I've problem like in title. I'm using ruby with Sinatra framework and trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.