EOFError: end of file reached issue with Net::HTTP

If the URL is using https instead of http, you need to add the following line: parsed_url = URI.parse(url) http = Net::HTTP.new(parsed_url.host, parsed_url.port) http.use_ssl = true Note the additional http.use_ssl = true. And the more appropriate code which would handle both http and https will be similar to the following one. url = URI.parse(domain) req … Read more

Rails Object to hash

If you are looking for only attributes, then you can get them by: @post.attributes Note that this calls ActiveModel::AttributeSet.to_hash every time you invoke it, so if you need to access the hash multiple times you should cache it in a local variable: attribs = @post.attributes

Rails: How to change the title of a page?

In your views do something like this: <% content_for :title, “Title for specific page” %> <!– or –> <h1><%= content_for(:title, “Title for specific page”) %></h1> The following goes in the layout file: <head> <title><%= yield(:title) %></title> <!– Additional header tags here –> </head> <body> <!– If all pages contain a headline tag, it’s preferable to … Read more

Ignoring time zones altogether in Rails and PostgreSQL

Postgres has two different timestamp data types: timestamp with time zone, short name: timestamptz timestamp without time zone, short name: timestamp timestamptz is the preferred type in the date/time family, literally. It has typispreferred set in pg_type, which can be relevant: Generating time series between two dates in PostgreSQL Internal storage and epoch Internally, timestamps … Read more