lundi 20 mai 2019

How to open a file with with ruby?

I am trying to open a file on rails user model with ruby and call it from user controller but it kept throwing me back wrong number of arguments (given 0, expected 1..3).

This is my file directory 'app' ,'assets', 'files', 'test_list.txt' 'app' ,'controllers', 'users controller'

can you help?thanks

class User < ApplicationRecord


  def self.my_method


    my_array = []


    file = File.join(Rails.root, 'app' 'models','assets', 'files', 'test_list.txt')
    File.open.each do  |line|

    my_array << line.gsub!(/\n?/, "")



    end

    return my_array.to_s

    end


end

class UsersController < ApplicationController

  require 'open-uri'
  require 'net/http'


  def show

    # uri = URI('https://gist.githubusercontent.com/Kalagan/3b26be21cbf65b62cf05ab549433314e/raw')
    #   data = Net::HTTP.get(uri)
    #   anagrams = data.split(/\n/)


    @vari = User.my_method
    @query = params[:query]
    @results = anagrams.select { |word| @query.split('').sort.join == word.split('').sort.join }



  end


end




Aucun commentaire:

Enregistrer un commentaire