ruby on rails - Iterating over JSON objects with HAML Partial -


i relatively new ruby on rails , haml. want name json object in haml.

i have in .rb file

campaigns = '[{"name":"campaign_1"},{"name":"campaign_2"},{"name":"campaign_3"}]' render "evaluate" , :locals => {:campaigns => campaigns} 

i want print out "campaign_1", "campaign_2" ... name. have in haml file. have tried several variations of loop none have quite worked. latest one.

this have in haml file:

- campaign in @campaigns         %input{:type => "checkbox"}           - campaign.name 

this gives me

undefined method `each' nil:nilclass`  

any appreciated. thank you!

important note: haml file partial

you can use locals pass values views. in controller code, need convert json hash , fix locals syntax:

json_campaigns = '[{"name":"campaign_1"},{"name":"campaign_2"},{"name":"campaign_3"}]' campaigns = json.parse json_campaigns render "evaluate" , :locals => {campaigns: campaigns} 

in view:

- campaigns.each |c|   %input{:type => "checkbox"}     = c["name"] 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -