Put a link in a flash[:notice]

后端 未结 8 1478
天涯浪人
天涯浪人 2020-12-04 23:31

I am learning Ruby and Rails.

I have a Ruby on Rails project that tracks jobs a server is running. Right now, when I manually create a new job, it announces:

<
相关标签:
8条回答
  • 2020-12-05 00:28

    I may be missing something obvious, but you should just be able to do

    flash[:notice] = %Q[Created job number <a href="/jobs/list?job=#{update.id}">#{update.id}</a>]
    

    and then just make sure you're not escaping the content of the flash when you display it in your view.

    0 讨论(0)
  • 2020-12-05 00:29

    The @template instance variable is no longer available in Rails 3.

    Instead you can use this in your controller:

    flash[:notice] = "Successfully created #{view_context.link_to('product', @product)}.".html_safe
    

    Hope this helps :)

    0 讨论(0)
提交回复
热议问题