Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7654815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:21:10+00:00 2026-05-31T12:21:10+00:00

I am working on a webapp that contains the basic elements of a CMS

  • 0

I am working on a webapp that contains the basic elements of a CMS webapp. Users can clone the repo, run the rails server, and be taken to a page that allows them to rename the app from the current name, “framework”, to whatever they want. After a bit of debate here, I decided to put the renaming code into my controller (as opposed to in a rake file). But my problem is that my controller has trouble figuring out what’s going on. This is what my view looks like.

<h1>Rails Framework</h1>

<%= form_tag "/namer" do %>
  <%= text_field_tag "appname" %>
  <%= submit_tag "Name Your App" ,  :action => 'create' %>

<% end %>

And this is my controller.

class NamerController < ApplicationController

  def index
    render('new') 
  end  

  def new
    @appname = Namer.new
  end

  def create
    @appname = Namer.new(params[:appname])
    #first, change any instances of the term "framework" to the new name of the app   
    file_names = ['config/environments/test.rb', 'config/environments/production.rb', 
      'config/environment.rb']
    file_names.each do |file_name|
      text = File.read(file_name)
      File.open(file_name, "w") { |file| file << text.gsub("Framework", @appname) }
    end
    #next,change the rootpath away from namer#new
    file_name ='config/routes.rb'
    text = File.read(file_name)
    File.open(file_name, "w") { |file| file << text.gsub("namer#new", "pages#home") }
    flash[:notice] = "Enjoy your app."
    render('pages/home')
  end 

end

I also have a model called renamer. It’s very basic. I removed the “< Base::ActiveRecord” because there’s no database involved in this renaming process.

class Namer 
end

My problem is that when I enter a a new name into the form, rails returns an error that says:

TypeError in NamerController#create.  Can't convert Namer into String.

I am not sure why it is so eager to turn Namer into a string since I thought it was only using the @appname variable as a string. Any ideas on why this is failing?

UPDATE: So I’ve made some changes to the original code and here’s how it looks now. For some reason the code did successfully run and do the name change on some of the files it’s supposed to.

class NamerController < ApplicationController

  def index
    render('new') 
  end  

  def new
  end

  def create
    #first, change any instances of the term "framework" to the new name of the app   
    file_names = ['config/environments/test.rb', 'config/environments/production.rb', 
       'config/environment.rb']
    file_names.each do |file_name|
      text = File.read(file_name)
      File.open(file_name, "w") { |file| file << text.gsub("Framework", params[:appname]) }
    end
    #next,change the rootpath away from namer#new
    file_name ='config/routes.rb'
    text = File.read(file_name)
    File.open(file_name, "w") { |file| file << text.gsub("namer#new", "pages#home") }
    File.open(file_name, "w") { |file| file << text.gsub("post '/namer' => 
      'namer#create'", "") }
    flash[:notice] = "Enjoy your app."
    redirect_to(root_path)
  end 

end

For some reason when the code was semi-successful, it ended up deleting all of the congig/environments/test.rb file, which looks like this.

Framework::Application.configure do

  config.cache_classes = true
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=3600"
  config.whiny_nils = true
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_dispatch.show_exceptions = false
  config.action_controller.allow_forgery_protection    = false
  config.action_mailer.delivery_method = :test
  config.active_support.deprecation = :stderr
  config.assets.allow_debugging = true
end

I had accidentally moved around one of the lines in the routes folder, which somehow kept the renaming code from running. (No idea why). So I figure it may be related to the problem of having the test.rb file emptied of all text. Here is my routes.rb file.

Framework::Application.routes.draw do


  resources :users
  resources :sessions, :only => [:new, :create, :destroy]

  match '/signup',  :to => 'users#new'
  match '/signin',  :to => 'sessions#new'
  match '/signout', :to => 'sessions#destroy'

  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about' 
  match '/help',    :to => 'pages#help'


  post '/namer' => 'namer#create'    
  root :to => "namer#new"
  match ':controller(/:action(/:id(.:format)))'
end

SOLUTION:
This is what my Create method ended up looking like. And now it works just like I wanted it to.

  def create
    #first, change any instances of the term "framework" to the new name of the app   
    file_names = ['config/environments/test.rb', 'config/environments/production.rb', 
       'config/environment.rb']
    file_names.each do |file_name|
      text = File.read(file_name)
      File.open(file_name, "w") {|file| file << text.gsub("Framework", params[:appname])}
    end
    #next,change the rootpath away from namer#new
    file_name ='config/routes.rb'
    text = File.read(file_name)
    File.open(file_name, "w") { |file| file << text.gsub("namer#new", "pages#home") }

    file_name ='config/routes.rb'
    text = File.read(file_name)    
    File.open(file_name, "w") { |file| file << text.gsub("post '/namer' => 
       'namer#create'", "") }
    flash[:notice] = "Enjoy your app."
    redirect_to(root_path)
  end 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:21:12+00:00Added an answer on May 31, 2026 at 12:21 pm

    This line: text.gsub("Framework", @appname) is where the issue is. gsub is looking for a string/pattern as the second argument while you are passing it a whole object, @appname. Try @appname.to_s.

    Update

    Well you could just replace @appname in the gsub with param[:appname] and avoid the class entirely.

    Or in Namer you could do:

    class Namer
        attr_accessor :appname
    end
    

    and then do:

    def create
        @appname = Namer.new 
        @appname.appname = params[:appname]  @appname.appname
        ...
        text.gsub("Framework", @appname.appname)
        ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ipad webapp that will receive monthly changes. However I can
I'm working on a small webapp in Rails that simulates a score card for
I am just working on a basic webapp that implements spring + hibernate entitymanager
I'm working on a webapp that uses SCORM so it can be included in
I'm working on a webapp that allows users to create scavenger hunts. Trouble is,
I'm working on a webapp in jquery that, on older machines or machines without
So I'm working on this site web app that should let users easily chat
All, I'm working on a java webapp that we deploy in the Resin web
I am working on a webapp that uses both the Spring Framework and RESTEasy.
I am working on a Rail webapp. I have two models, User, which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.