#NA

Stack Overflow

A language-independent collaboratively edited question and answer site for programmers.

  • Writing beautiful Ruby

    idiom for "foo.nil? ? nil : foo.to_i"?

    stackoverflow.com 23 Apr '17, 2am

    def bar(foo) foo.to_i unless foo.nil? end But you don't really gain anything, IMO, except eliminating the ? ? . It's a character shorter, potentially more readable if you know Ruby. Don't know as it qualifies as "more concise" than the ternary. (I say "potentially" because it might be...

  • Common Ruby Idioms

    stackoverflow.com 22 Apr '17, 12am

    The magic if clause that lets the same file serve as a library or a script: if __FILE__ == $0 # this library may be run as a standalone script end Packing and unpacking arrays: # put the first two words in a and b and the rest in arr a,b,*arr = *%w{a dog was following me, but then he ...

  • on rails - Order query by number of times one model has another

    stackoverflow.com 25 Mar '17, 6am

    I have the following structure: User model: id, .. Event model: id, .. UserMapEvent model: user_id, event_id For example the UserMapEvent table might have the following records: User_id - Event_id 1 - 1 1 - 2 3 - 1 4 - 1 I'm using this structure to save when a user likes an event. Now...

  • on Rails - Emoji not saved in MySQL

    stackoverflow.com 31 Mar '17, 6pm

    I'm working on a Rails app where users can upload photos to their profiles. Every photo has a title, which is supposed to support emoji. Despite changing encoding of the table to utf8mb4 and modifying database.yml when i try to save a photo with emoji in its title MySQL returns an err...

  • How to insert post data in mongodb using ruby on rails

    stackoverflow.com 06 Mar '17, 10am

    I am trying to insert article post data in mongodb collection but I got below error. Mongoid::Errors::NoParent at /articles message: Cannot persist embedded document Article without a parent document. summary: If the document is embedded, in order to be persisted it must always have a...

  • How to remove bootstrap-sass from Ruby on Rails 5.0.2

    stackoverflow.com 24 Mar '17, 4am

    I'd like to remove bootstrap-sass 3.3.7 from ruby on rails. I installed gem bootstrap-sass a month ago. However, I created design by myself. So I would like to uninstall bootstrap-sass. I tried gem uninstall gem bootstrap-sass rake assets:clean but, bootstrap was not removed.

  • javascript - Ruby on rails live update

    stackoverflow.com 28 Feb '17, 4pm

    Okay, what i am looking for is a way to get an ajax script to run in the background of a page and look to see if there is a new record in the database and if there has grab that record and display that on my page. i also do not want to use plugins i would rather do this myself as i pr...

  • No automatic line break when exceeding textarea in form input field

    html - No automatic line break when exceeding textarea in form input field

    stackoverflow.com 13 Feb '17, 3am

    I have a form with an input field for a string. I resized the 'textarea' height to fit with the style I'm trying to achieve but I found two unexpected problems which I haven't been able to fix. The text input and placeholder values are centred vertically in the textarea. I'd like them...

Related