erb

Ruby ternary operator in erb?

非 Y 不嫁゛ 提交于 2019-12-09 02:41:55
问题 How can I make this code look better: <%=raw manuscript.uploaded_to_s3? ? "<span style=\"color:green;\">" : "<span style=\"color:red;\">" %> That is, can the HTML go outside of the ERB block making this easier to read? 回答1: <span style="color:<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>"> I would advocate a CSS class rather than style attribute 8P: <span class="<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>"> 来源: https://stackoverflow.com/questions/5248625/ruby-ternary-operator-in

How to add a checkbox for each row in Rails 3.2 index page?

这一生的挚爱 提交于 2019-12-08 13:41:30
问题 We would like to add a checkbox to each row on Rails index page to flag for the row. This checkbox is not part of the object (no checkbox boolean in database). When the index page shows, a user can check the box to trigger an event for the row in following process: #objects/checkbox_index.html.erb <table> <tr> <th>CheckBox</th> <th>Object Name</th> <th>Object ID</th> </tr> <%= @objects.each do |obj| %> <tr> <td><%= checkbox %></td> <td><%= obj.name %></td> <td><%= obj.id %></td> </tr> <% end

How do I hide and show the contents contents of a modal?

谁说我不能喝 提交于 2019-12-08 08:59:31
问题 In my modal, I have a link. The link is written as follows: <%= link_to "HIDE DETAILS", '#', class:'right' %> When I click on that link, I want the link to display "SHOW DETAILS" instead of "HIDE DETAILS" and the div with id= "details" should disappear off the view with all its children. And when the link is clicked again, the link shows "HIDE DETAILS" and the contents of the div with details to show and vice-versa (toggle functionality). And when the page is first displayed, I want the div

Adding a text area by clicking a button-rails 4

跟風遠走 提交于 2019-12-08 07:33:24
问题 I have a list of 5 question text-fields in a form for a user to enter questions. I want a user to be able to add a question by clicking a "+" button. how can i do this? I have this for a sample: <%= simple_form_for(@quiz, html: {class: 'form-vertical' }) do |f| %> <%= render 'shared/error_messages_question' %> <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question." %> <% end %> 回答1: It's pretty easy to set up with javascript/coffeescript , Since

ERB like library for C#

喜你入骨 提交于 2019-12-08 05:26:30
问题 I am looking to find a librray that emulates part of the capabilities of Ruby's ERB library. ie substitute text for variables between <% and %>. I dont need the code execution part that ERB provides but if you know of something that has this I would be super appreciative. 回答1: Have a look at TemplateMachine, I haven't tested it, but it seems to be a bit ERB-like. 回答2: I modified a class I used to test some things a while ago. It's not even nearly as good as ERB but it gets the job done

can you use embedded ruby in custom javascript files in rails?

我的梦境 提交于 2019-12-08 04:55:24
问题 How does one embed ruby code in javascript for rails? I know you can do this easily in javascript responders for action methods (for e.g. in create.erb.js). But is there a way to do this for other custom javascript files that are included in the application using javascript_include_tag? For e.g. in create.erb.js I can write code such as <%= if current_user_name ="xyz" %> Is there a way to have this type of embedding in a custom js file such as custom.js that is used across the application and

Indent multiline string in ERB

和自甴很熟 提交于 2019-12-08 04:13:36
问题 I have a string from an external library that looks like this: s = " things.each do |thing|\n thing += 5\n thing.save\n end\n\n" This input string isn't going to change. I need to insert it into a file using ERB. e.g.: erb = ERB.new("<%= s %>") File.write("test.txt", erb.result(instance_eval('binding')) My problem is the indentation. Without making any changes to the string, the file will be written like this: things.each do |thing| thing += 5 thing.run end Note the indentation. What I want

Rails I18n translations scoping

早过忘川 提交于 2019-12-07 09:03:30
问题 Writing a fully translated app can become tedious. Is there a way to set a default translation scope for the current context ? Example : I am writing inside a partial _deadlines.html.erb in the show.html.erb action of my ProjectsController Now because I am trying to be a good programmer, I am scoping all my translations. I would like to produce the following tree projects: deadlines: now: "Hurry the deadline is today !" .... How can I make it less tedious than writing each time the full scope

Why is this an error with ERB?

纵饮孤独 提交于 2019-12-07 03:13:24
问题 <div class='row'> <%= form.field_container :name do %> <%= form.label :name, raw('Name' + content_tag(:span, ' *', :class => 'required')) %> <%= form.text_field :name, :class => 'fullwidth' %> <%= form.error_message_on :name %> <% end %> </div> Why is this producing the following error? $ erb -x -T - test.erb | ruby -c -:3: syntax error, unexpected ')' ...form.field_container :name do ).to_s); _erbout.concat "\n" ... ^ -:9: syntax error, unexpected $end, expecting ')' 回答1: If you look at the

Adding a text area by clicking a button-rails 4

﹥>﹥吖頭↗ 提交于 2019-12-07 00:37:31
I have a list of 5 question text-fields in a form for a user to enter questions. I want a user to be able to add a question by clicking a "+" button. how can i do this? I have this for a sample: <%= simple_form_for(@quiz, html: {class: 'form-vertical' }) do |f| %> <%= render 'shared/error_messages_question' %> <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question." %> <% end %> It's pretty easy to set up with javascript/coffeescript , Since it's Rails let's use coffeescript , You should have a coffeescript file under your app/assets/javascripts