【问题标题】:How to use notify.js with a button in rails 4?如何在 Rails 4 中使用带有按钮的 notify.js?
【发布时间】:2015-01-30 07:08:31
【问题描述】:

我是 Rails 新手。我想使用 notify.js 显示通知。我已经下载了 notify.js 文件并将其放入 app/assets/javascripts 中。现在 <script> $.notify("Hello", "success" ); </script>

完美运行。但是我想在单击按钮后执行此操作。

&lt;%= link_to image_tag("done.png", :title =&gt; 'Mark as Done', :class =&gt; 'controller_images'), task_path(task), :method =&gt; :put %&gt;

这是我的按钮代码。

def create
@task = Task.new(task_params)
if @task.save
  redirect_to tasks_path, :notice => "Your new Task is added successfully!"

else
  render "new"
end
end

这是创建新任务的控制器类的代码。 我想在成功创建任务时使用 notify.js 而不是使用:notice

请有人帮帮我。提前致谢。

【问题讨论】:

    标签: javascript jquery ruby-on-rails jquery-plugins


    【解决方案1】:

    这可能是一个例子,但我必须说的不是最好的情况。我宁愿将通知注入正文中的某个位置,并继续寻找任何通知/错误/其他类型的通知,并使用可用的解析数据调用 notify.js。

    <script type="text/javascript">
         $(function(){
            var notice = "<%= flash[:notice] %>"
             $.notify(notice, "success" );
         })
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-20
      • 2017-03-05
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多