ruby

Check if two urls are for the same website

懵懂的女人 提交于 2021-02-11 12:50:59
问题 I'm looking for a way to compare two urls. I can do: URI('http://www.test.com/blabla').host to have the base name, but this not reliable. For example: URI('http://www.test.com/blabla').host == URI('http://test.com/blabla').host returns false , but they can be the same site. To have the IP address is not reliable too because if I do: IPSocket.getaddress(URI('http://hello.herokuapp.com').host) == IPSocket.getaddress(URI('http://test.herokuapp.com').host) It returns true , but they are not the

How to fix 'Your Ruby version is 2.3.3, but your Gemfile specified 2.5.2'

自古美人都是妖i 提交于 2021-02-11 09:42:27
问题 I got an error: Your Ruby version is 2.3.3, but your Gemfile specified 2.5.2 with running bundle install . Besides, ruby -v shows ruby 2.5.2p104 (2018-10-18 revision 65133) [x86_64-linux] . OS: Debian 9 Problem with bundler was solved with: Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0 But now there is the same error with rails s 回答1: The problem was solved by, rvm reinstall ruby-2.5.2 rvm default use ruby-2.5.2 bundle install bin/rails s 来源: https://stackoverflow.com/questions

two versions of ruby installed, how to fix that?

青春壹個敷衍的年華 提交于 2021-02-11 08:10:37
问题 I found out that I have two versions of ruby installed on OSX 10.6.2 how can I uninstall the older version and make sure that everything is fine, the path point to the other one? bash-3.2$ /usr/local/bin/ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0] bash-3.2$ /usr/bin/ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] bash-3.2$ $PATH bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory bash-3.2$ whereis ruby /usr/bin

two versions of ruby installed, how to fix that?

一世执手 提交于 2021-02-11 08:10:06
问题 I found out that I have two versions of ruby installed on OSX 10.6.2 how can I uninstall the older version and make sure that everything is fine, the path point to the other one? bash-3.2$ /usr/local/bin/ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0] bash-3.2$ /usr/bin/ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] bash-3.2$ $PATH bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory bash-3.2$ whereis ruby /usr/bin

Overriding the << method for instance variables

无人久伴 提交于 2021-02-11 07:37:36
问题 Let's suppose I have this class: class Example attr_accessor :numbers def initialize(numbers = []) @numbers = numbers end private def validate!(number) number >= 0 || raise(ArgumentError) end end I would like to run the #validate! on any new number before pushing it into the numbers : example = Example.new([1, 2, 3]) example.numbers # [1, 2, 3] example.numbers << 4 example.numbers # [1, 2, 3, 4] example.numbers << -1 # raise ArgumentError Below is the best I can do but I'm really not sure

How to pull Instagram image caption text using the Instagram API?

瘦欲@ 提交于 2021-02-11 06:17:52
问题 I'm using the Instagram api to build a site in Ruby on Rails. I can't seem to figure out how to pull caption text with any of the images, and it doesn't seem to state how to do this anywhere in the documentation. Is it possible using the api or do I have to use something else? I've attached 2 very simple code snippets to illustrate my problem below Ruby: class HomeController < ApplicationController def index def index @instagram = Instagram.tag_recent_media("blablabla", {:count => 50}) end

How to pull Instagram image caption text using the Instagram API?

江枫思渺然 提交于 2021-02-11 06:17:25
问题 I'm using the Instagram api to build a site in Ruby on Rails. I can't seem to figure out how to pull caption text with any of the images, and it doesn't seem to state how to do this anywhere in the documentation. Is it possible using the api or do I have to use something else? I've attached 2 very simple code snippets to illustrate my problem below Ruby: class HomeController < ApplicationController def index def index @instagram = Instagram.tag_recent_media("blablabla", {:count => 50}) end

How to pull Instagram image caption text using the Instagram API?

送分小仙女□ 提交于 2021-02-11 06:16:38
问题 I'm using the Instagram api to build a site in Ruby on Rails. I can't seem to figure out how to pull caption text with any of the images, and it doesn't seem to state how to do this anywhere in the documentation. Is it possible using the api or do I have to use something else? I've attached 2 very simple code snippets to illustrate my problem below Ruby: class HomeController < ApplicationController def index def index @instagram = Instagram.tag_recent_media("blablabla", {:count => 50}) end

How to pull Instagram image caption text using the Instagram API?

廉价感情. 提交于 2021-02-11 06:14:01
问题 I'm using the Instagram api to build a site in Ruby on Rails. I can't seem to figure out how to pull caption text with any of the images, and it doesn't seem to state how to do this anywhere in the documentation. Is it possible using the api or do I have to use something else? I've attached 2 very simple code snippets to illustrate my problem below Ruby: class HomeController < ApplicationController def index def index @instagram = Instagram.tag_recent_media("blablabla", {:count => 50}) end

how to get the persistent cookie value and session cookie value in rails application

大憨熊 提交于 2021-02-11 01:14:08
问题 Im developing ruby on rails application. I want to get the persistent cookie value and session cookie value in the application. Can any please guide me on this I have read that request.session_options[:id] will fetch the session_id, is that the one that is usually stored in session cookie? Please guide me if my way of understanding is wrong.Thanks in advance 回答1: In Rails, it is simple as calling the session or cookies hash. # Set a simple session cookie cookies[:user_name] = "david" # Read a