Q:

How to pass text from gets.chomp to a file

I want to push resources :#{get} to the bottom of resources :posts.
get = gets.chomp
@file = File.open('config/routes.rb','r+')
myString = "
  resources :#{get}s
"

Rails.application.routes.draw do
  resources :users do
    resources :posts
  end
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

The result is:
Rails.application.routes.draw do
  resources :users do
    resources :posts
    resources :categories
  end
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

How do I pass data from user input to a file?

A:

Making the assumption that there will only ever be one resources :posts in your routes file, a simple example could be done like:
require 'active_support/core_ext/string/inflections' # for `pluralize`

get = gets.chomp
lines = File.read("config/routes.rb").split(/\n/)

# find the line of the file we want to insert after. This assumes
# there will only be a single `resources :posts` in your routes.
index = lines.index { |line| line.strip == 'resources :posts' }
# duplicate the existing line and replace 'posts' with the pluralized form
# of whatever the user input to gets, we do it this way to keep indentation
new_line = lines[index].gsub(/posts/, get.pluralize)

# insert the new line on the line after the `resources :posts` and then write
# the entire thing back out to 'config/routes.rb'
lines.insert(index + 1, new_line)
File.open("config/routes.rb", "w") { |f| f.write(lines.join("\n")) }

Depending on what you're trying to do, though, you may find it useful to look into Rails Generators.
before
Rails.application.routes.draw do
  resources :users do
    resources :posts
  end
end

execute
$ echo category | ruby example.rb

after
Rails.application.routes.draw do
  resources :users do
    resources :posts
    resources :categories
  end
end

