ruby-on-rails - Rails - 在 flash 通知中传递变量

标签 ruby-on-rails ruby variables

我一直在尝试在使用 #{variable} 创建帖子时出现的 flash 通知中添加一个变量

但我一定是遗漏了什么,因为我收到的唯一消息是“#{variable}”。

这是我的 Controller :

 def create

    @participant = Participant.new(params[:participant])

    respond_to do |format|
      if @participant.save
        mail = params[:email]
        format.html { redirect_to @participant, notice: 'Thanks, We will be sending out instructions to:  #{mail}' }
        format.json { render json: @participant, status: :created, location: @participant }
      else
        format.html { render action: "new" }
        format.json { render json: @participant.errors, status: :unprocessable_entity }
      end
    end
  end

我也一直在尝试将@participants 作为变量,但是,除了消息中实际的“#{@participants}”,我仍然没有得到任何东西。

最佳答案

我猜你在参与者表格中填写了邮件,所以试试:

   email = params[:participant][:mail]

""代替''

关于ruby-on-rails - Rails - 在 flash 通知中传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15382306/

相关文章:

ruby-on-rails - 全局化轮胎 Elasticsearch 和重音折叠

ruby-on-rails - Nginx 没有为我的测试 Rails 应用程序提供服务

ruby-on-rails - 将密码重置发送到其他电子邮件 - Devise

ruby - 通过代码创建数组

java - 为什么 Java 编译器会提示局部变量没有在这里初始化?

python - Python- “Local x variable referenced before assignment”(关闭)

ruby-on-rails - 无法使用 .to_i 将数组中的第一个元素转换为整数

html - 替换除链接之外的所有文本

ruby-on-rails - 将 HashMap 作为对象的属性进行访问

variables - Snowflake使用变量来设置数据库和架构