Rails - 在表单参数前添加一个字符串

时间:2013-09-10 20:22:36

标签: ruby-on-rails ruby ruby-on-rails-3 forms ruby-on-rails-3.2

我迷失了,似乎无法在任何地方找到解决方案......

我想要做的就是当他们通过外部API提交表单时,可以在我的用户名前面添加一些问候语......所以没有任何内容保存到我的数据库中

我想要做的就是这个

 "Web inquiry from Jon Doe"

所以我有一张表格

  <%= text_field :subject %>

当用户将其姓名放入其中并提交表单时,我的客户可以转到其发布的外部网站并查看

 "Web inquiry from Jon Doe"

所以我只需要能够实现

 Web inquiry from 

部分到表格上的名字?

请帮助我......你唯一的希望

继承我的控制器

class Website::ContactsController < Website::WebsiteApplicationController
  def new
    @contacts = Form.new
  end

  def create
    @contacts = Form.new(params[:contacts])
    @contacts.post_tickets(params[:contacts])
    if @contacts.valid?
      flash[:success] = "Message sent! Thank you for conacting us."
      redirect_to new_contact_path
    else
      flash[:alert] = "Please fill in the required fields"
      render action: 'new'
    end
  end
end

继承人我的表格

 = form_for(:contacts, url: contacts_path) do |f| 
   = f.error_messages
   = f.label :subject, "Name"
   %span{style: 'color: red'} *
   = f.text_field :subject, class: "text_field width_100_percent"
    %br
    %br    
    = f.label "Email"
    %span{style: 'color: red'} *
    %br    
    = f.email_field :email, class: "text_field width_100_percent"
    %br
    %br
    = f.label "Phone"
    %br    
    = f.text_field :custom_field_phone_number_28445, name: 'contacts[custom_field][phone_number_28445]', class: "text_field width_100_percent"
    %br
    %br
    = f.label "Company"
    %br    
    = f.text_field :custom_field_company_28445, name: 'contacts[custom_field][company_28445]', class: "text_field width_100_percent"
    %br
    %br
    = f.label "Question(s), and/or feedback"
    %span{style: 'color: red'} *
    %br
    = f.text_area :description, class: "text_field width_100_percent", style: 'height: 100px;'
    %br
    %br
    = f.submit "Submit", class: 'btn btn-warning'

1 个答案:

答案 0 :(得分:0)

这不够吗?

message = "Web inquiry from " + params[:subject]