- Published on
Railsで正規表現置換ツールを作成する
- Authors
- Name
- Shou Arisaka / 有坂翔
// show.html.erb
<%= form_tag('/dev/index', method: :post) do %>
<%= text_area_tag :content %>
<%= text_field_tag :kw_before %>
<%= text_field_tag :kw_after %>
<%= submit_tag("submit") %>
<% end %>
// dev_controller.rb
def index
@content = params[:content]
@content.gsub!(/#{params[:kw_before]}/, params[:kw_after])
Userinfo.create(name: @content)
end
// index.html.erb
<%= @content %>