我有以下.txt文件:
Marco
Paolo
Antonio
Run Code Online (Sandbox Code Playgroud)
我想逐行读取它,并且对于每行我想为变量分配.txt行值.假设我的变量是$name
,流程是:
$name
="Marco"$name
$name
="保罗"我必须在不使用CSS类的情况下更改link_to标签颜色,我该怎么办?我尝试过像
<%= link_to item.description, {}, {:style=>'color:#FFFFFF;', :class => "css_class"} %>
Run Code Online (Sandbox Code Playgroud)
但它不适用于ruby 1.9.2和rails 3.1
我使用Prawn作为pdf生成器将图像添加到PDF中时遇到问题.我正在尝试使用以下代码添加图像:
def header
text "something"
image "#{Prawn::DATADIR}/images/logo_small.png"
end
Run Code Online (Sandbox Code Playgroud)
但app回复我的错误如下:
uninitialized constant Prawn::DATADIR
Run Code Online (Sandbox Code Playgroud)
哪里出错了?
PS我的应用程序在Rails 3.1和Ruby 1.9.2上运行.
我的Rails 3.1应用程序中有一个由多个对象组成的数组:
[#<Hardware id: 10, brand_id: 5, model: "B4200", description: "Stampante OKI B4200", typology_id: 3, sub_typology_id: 10, created_at: nil, updated_at: nil>, #<Hardware id: 19, brand_id: 9, model: "JetLab", description: "JetLab - 600 ", typology_id: 5, sub_typology_id: nil, created_at: nil, updated_at: nil>]
Run Code Online (Sandbox Code Playgroud)
我想从这个数组中删除一个对象.使用Rails控制台,我试图做一些事情(尝试删除第一个对象):
array.pop=#<Hardware id: 10, brand_id: 5, model: "B4200", description: "Stampante OKI B4200", typology_id: 3, sub_typology_id: 10, created_at: nil, updated_at: nil>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我怎样才能做到这一点?
更新:我的目标不是在数组上弹出最后一个元素,而是使用mysql搜索查询找到一个通用对象(数组中的任何位置).
这是我的看法:
@bulk_objects.each do |bulk_warehouse|
bulk_error = @wh_errors[:"bulk_warehouse#{@count}"] if @wh_errors
-%>
<tr class="<%= cycle("odd", "even") %>">
<%= hidden_field_tag("bulk_warehouse_id#{@count}",bulk_warehouse.id) %>
<td><%= text_field_tag("bulk_warehouse_asset#{@count}", bulk_warehouse.asset, :disabled => true)%></td>
<td><%= text_field_tag("bulk_warehouse_serial#{@count}", bulk_warehouse.serial, :disabled => true) %></td>
<td><%= check_box_tag "enable_record#{@count}",1,false,{:onclick => "bulk_warehouse_asset#{@count}.disabled =
bulk_warehouse_serial#{@count}.disabled =
!this.checked;"}%></td>
<td class="last">
<%= link_to "#{t("web-app-theme.delete", :default => "Delete")}", bulk_warehouse_path(bulk_warehouse), :method => :delete, :confirm => "#{t("web-app-theme.confirm", :default => "Are you sure?")}" %>
</td>
</tr>
</div>
<% @count = @count +1 %>
<% end -%>
</table>
<div class="actions-bar wat-cf">
<div class="actions">
</div> …
Run Code Online (Sandbox Code Playgroud) 我正在使用Prawn 2-0.2.4在Rails 3.1应用程序上制作pdf.我是一个很好的问题; 我无法看到text_box边框; 这是我的行动:
def firma_conducente
text_box "Firma Conducente ________ Firma Cessionario _____", :rotate => 270, :size => 10, :at=> [500,500], :width => 600, :height => 1200 do
stroke_color = 'FFFF00'
end
end
Run Code Online (Sandbox Code Playgroud)
我可以在pdf生成的文件中看到文字,但我不知道怎样才能看到边框.此外,有没有办法将此text_box放在每个文档的页面上?
我正在使用Rails 3.1并且我的视图返回到控制器这个参数(我在web服务器日志上检查过它):
"warehouse"=>{"asset"=>"turiturira", "serial"=>"caricarira", "project_id"=>"1", "hardware"=>{"brand_id"=>"21"}, "hardware_id"=>"60", "state_id"=>"4", "position_id"=>"1", "logicalwarehouse_id"=>"3", "extra_id"=>"3"}, "bulk_warehouse_serial270"=>"t", "bulk_warehouse_asset270"=>"test", "enable_record270"=>"1", "bulk_warehouse_serial271"=>"uela2", "bulk_warehouse_asset271"=>"bela2", "enable_record271"=>"1"}
Run Code Online (Sandbox Code Playgroud)
现在我应该使用这个参数.我知道如果我需要所有仓库参数,我可能会做一些事情,例如:
@warehouse = Warehouse.new(params[:warehouse])
Run Code Online (Sandbox Code Playgroud)
但如果我需要"仓库"内的单个参数,我该怎么办?假设我想将@serial变量设置为"bulk_warehouse_serial270"值("test"); 我应该做的事情如下:
@serial = params(:warehouse[:bulk_warehouse_serial270])
Run Code Online (Sandbox Code Playgroud)
或者改为:
@serial = params(:warehouse)params(:bulk_warehouse_serial270)
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
在我的Rails 3.1,ruby 1.9.2应用程序中,我有一个Object'Post',它有几个字段,如id,created_at,updated_at,name,description ....在我的视图中,我希望显示post.created_at字段过滤日期:我解释得更好:在我看来,我想要的东西如下:
但是HTML必须呈现如下内容:2011-30-06而不是2011-30-06 11:04 am
换句话说,我想只显示日期而不是小时,我该怎么办?