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

  • SEARCH
  • Home
  • 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 8900891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:12:43+00:00 2026-06-15T01:12:43+00:00

I have two DataMapper models: class Address include DataMapper::Resource property :id, Serial property :url,

  • 0

I have two DataMapper models:

class Address
  include DataMapper::Resource

  property :id, Serial
  property :url, String, :required => true

  has n, :logs
end

class Log
  include DataMapper::Resource

  property :id, Serial
  property :useragent, String

  belongs_to :address
end

I use Sinatra to create new addresses, and in another method logs which belongs to these addresses.

  # page after posting a form
  post '/' do
    @messages = []

    if (params[:url] =~ URI::regexp).nil?
      @messages.push('URL is not valid!')
    else
      address = Address.create(:url => params[:url])

      base36 = address.id.to_s(36)
      @messages.push(request.url + base36)
    end

    erb :index
  end

  # redirection from a short url
  get '/:base36' do |base36| 
    # probably not necessary...
    if base36 =~ /[[:alnum:]]+/
      begin
        id = base36.to_i(36)
        address = Address.get(id)

        log = Log.create(:useragent => request.user_agent)
        address.logs << log
        # log.save
        address.save
        # address.logs.save

        address.logs.length.to_s
        # redirect address.url
      rescue
        redirect '/'
      end
    else
      redirect '/'
    end
  end

The problem is, that new logs aren’t stored in a database. address.logs.length.to_s Is 1 on every page reload (it should be incrementing). When I do this (in another method):

logs = Address.get(id).logs
@views = logs.length

views are always 0. What is wrong with this code?


OK, so I tried do push to the String field too long useragent. String is limited to 50 characters. People on #datamapper irc channel helped me, .save method returns false in this case and data isn’t stored.

  • 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-06-15T01:12:44+00:00Added an answer on June 15, 2026 at 1:12 am

    OK, so I tried do push to the String field too long useragent. String is limited to 50 characters. People on #datamapper irc channel helped me, .save method returns false in this case and data isn’t stored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 related models: class Transaction include DataMapper::Resource property :id, Serial property :volume,
I've got two models that look like this class Stage include DataMapper::Resource property :id,
Have two bean definitions: file a.xml <bean id=A class=com.A> <property name=bClass ref=B/> </bean> file
I have two classes class Product extends DataMapper { var $has_one = array('category'); }
So I have two objects. class Product extends DataMapper { var $has_many = array('productrating');
Have two folders with approx. 150 java property files. In a shell script, how
I have two classes (MVC view model) which inherits from one abstract base class.
Let's say I have two tables: Book and Category . Book has a foreign
I have two models that are associated. I have an Artist model and a
I have two XML files. The first XML has a bunch of nodes that

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.