I have a table Company with companyid and companyname, and a table Config for my company configuration that have id, companyid, companyname, config that is in my dropdown generate by rails g scaffold
how can I override/change Ruby's Save/create button on creating my new config? Is it right to have my companyname on the config table or is it better to remove it and have a method geyCompanyName(id)?
I'm new to Ruby and just trying to follow the tutorial
Controller looks like
def index
@company_config = CompanyConfig.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @company_config }
end
end
def show
@@company_config = CompanyConfig.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @company_config }
end
end
def new
@company_config = ComapnyConfig.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @company_config }
end
end
def edit
@company_config = CompanyConfig.find(params[:id])
end
def create
@company_config = CompanyConfig.new(params[:company_config])
respond_to do |format|
if @company_config.save
format.html { redirect_to @company_config, notice: 'Config was successfully created.' }
format.json { render json: @company_config, status: :created, location: @company_config }
else
format.html { render action: "new" }
format.json { render json: @@company_config.errors, status: :unprocessable_entity }
end
end
end
I tried to look on Controller create but not sure how to edit it to meet what I want to accomplish.
my view looks like
<%= simple_form_for(@company_config) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :companyid, collection:build_company_select_array %>
<%= f.input :companyname %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>