Dynamically generating selector, hyphen problem

Rails 3.1.3

I would like to generate something like this.

× Successful!

I tried,

content_tag :div, msg, :class => “alert alert-success” do
content_tag :a, “x”, :class => “close”, :data-dismiss => “alert”
end

But the problem is the hyphen, “-”, where “:data-dismiss =>…”
Do you think we can avoid this problem?

soichi

Have you tried “data-dismiss”.to_sym?

On Mar 17, 2012, at 4:52 PM, Soichi I. wrote:

I tried,

content_tag :div, msg, :class => “alert alert-success” do
content_tag :a, “x”, :class => “close”, :data-dismiss => “alert”
end

But the problem is the hyphen, “-”, where “:data-dismiss =>…”
Do you think we can avoid this problem?

You can either use a bare string (‘data-dismiss’ => “alert”) or you can
use quotes in the symbol name (:“data-dismiss” => “alert”).

Walter

A bare string works!

Thanks, everyone!

soichi

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs