I am creating an app where users could enter their name that will be returned as chemical symbols (when matching).
So I managed to do in the console like:
symbols = {
"ac" => "Ac",
"al" => "Al",
"am" => "Al",
"br" => "Br",
"ba" => "Ba",
"cr" => "Cr"
}
puts "Get your chemical name!"
name = gets.chomp
name.gsub!(/#{symbols.keys.join('|')}/, symbols)
puts name
Now I'd like to make it works in the app but I don't know how to create the method ? I want it to be displayed only in the views/show
= @convertor.name
= link_to 'Edit', edit_convertor_path(@convertor)
= link_to 'Back', convertors_path
shall I create the method in my model or else where?
class Convertor < ActiveRecord::Base
def get_chemical_name(name)
symbols = {
"ac" => "Ac",
"al" => "Al",
"am" => "Al",
"br" => "Br",
"ba" => "Ba",
"cr" => "Cr"
}
name.gsub!(/#{symbols.keys.join('|')}/, symbols)
puts name
end
end
so in my view showI tried something like =@convertor.get_chemical(name)
but unsuccessful..
I need your help please