Rails 3.1.RC4
Devise 1.4.2
我已经将first_name和last_name列添加到设计用户表中.然后我习惯了控制台为我的第一个用户添加first_name和last_name.
现在,application.html.erb在我确定用户登录后,由于以下代码,我显示了我的名字和姓氏:
<%= current_user.first_name %> <%= current_user.last_name %>(<%= current_user.email %>)
Run Code Online (Sandbox Code Playgroud)
这是我的问题:当我尝试通过我创建的新用户表单注册一个新用户时,first_name和last_name没有存储在数据库中或者其他东西......因为当我使用新用户登录时我拥有的代码在我的application.html.erb不显示名字和姓氏.
这是以下名称中的名字和姓氏的文本字段new.html.erb:
<p><%= f.label :first_name %><br />
<%= f.text_field :first_name %></p>
<p><%= f.label :last_name %><br />
<%= f.text_field :last_name %></p>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
Run Code Online (Sandbox Code Playgroud)
我还想知道如何为我创建的这些新列添加验证(first_name和last_name).
提前致谢!
我正在编写一个 Sublime2 插件并且有点挣扎。
代码是:
def run(self, edit):
self.edit = edit
self.view.window().show_input_panel("New Controller and View Path (ex: client_area/index )", "", self.trigger, None, None)
def trigger(self, user_entry):
formatted_entry = user_entry.encode('utf-8')
print formatted_entry.__class__
print formatted_entry
if formatted_entry.slice('/')[0] == '':
#some code
Run Code Online (Sandbox Code Playgroud)
输出是:
<type 'str'>
client_area/index
Traceback (most recent call last):
File "./PluginName.py", line 27, in trigger
AttributeError: 'str' object has no attribute 'slice'
Run Code Online (Sandbox Code Playgroud)
我怎么了'str' object has no attribute 'slice'?(Python 版本为 2.6)
我的Rails代码中有以下视图:
<%= gmaps4rails(@ map,{"processing"=>'json','auto_adjust'=> false,'auto_zoom'=> false,'zoom'=> 10})%>
我的地图上只有一个标记.当我显示地图时,尽管我在上面设置了选项,但缩放始终设置为最大值.我忘记了一个选择吗?
我试图点击显示一些信息的地图.我正在使用谷歌API
Gmaps4Rails.callback = function() {
google.maps.event.addListener(map, "click", function() {
alert("You clicked the map.");
});
};
Run Code Online (Sandbox Code Playgroud)
但这不起作用,它什么都没有
我正在尝试创建一个名为countcash的表单,允许用户输入实际的季度,硬币,镍币,便士,二十,数十,五,一的数量,然后输入现金箱中任何其他项目的货币价值,然后当他们点击提交时,我想总计这些值并设置我当前班次记录的cashstart字段.
真正的问题是,我不确定我的表单应该是什么样子以及在这种情况下应该如何设置控制器/模型.
我有一个shift_id保存在一个session[:shift_id]变量中,其中id的转移是我想用计算的cashstart修改的转移.
<%= form_for %>如果我想正确地遵循MVC,那么标签需要看起来是什么?如何设置控制器/模型以使用计算值更新数据库?我该怎么设置路线?我在堆栈溢出或其他rails论坛上找不到这样的东西(尽管你认为通过多个文本字段修改单个属性会非常简单)
作为参考,这是我以前使用的形式(无济于事)
应用/视图/ countcash.html.erb
<%= form_for @shift do |f| %>
<table>
<tr>
<th>Coins</th>
<th></th>
</tr>
<tr>
<td>Quarters: </td>
<td><%= f.text_field :quarters %><br /></td>
</tr>
<tr>
<td>Dimes: </td>
<td><%= f.text_field :dimes %><br /></td>
</tr>
<tr>
<td>Nickels: </td>
<td><%= f.text_field :nickels %><br /></td>
</tr>
<tr>
<td>Pennies: </td>
<td><%= f.text_field :pennies %><br /></td>
</tr>
<tr>
<th>Bills</th>
<th></th>
</tr>
<tr>
<td>Twenties: </td>
<td><%= f.text_field :twenties %><br /></td>
</tr>
<tr>
<td>Tens: </td>
<td><%= f.text_field :tens …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个具有年属性的数据库,但我遇到了一些困难.我创建了脚手架并尝试使用以下代码修改_form.html.erb:
<%= f.date_select :year, :start_year=>2000, :end_year=>Time.now.year %>
Run Code Online (Sandbox Code Playgroud)
试图运行rails服务器并给我这个错误:
1 error(s) on assignment of multiparameter attributes
Run Code Online (Sandbox Code Playgroud)
我意识到我只想要一年而不是一天或一个月.有没有办法做到这一点?我试过:discard_month => true但是只是隐藏它,但仍然存储它.
提前致谢
我有一个哈希,其格式为密钥"YYYY-MM".
我想按升序对哈希进行排序.以下是我想要的:
{"2013-05" => 2 , "2013-06" => 4 , "2013-07" =>10 , ... }
Run Code Online (Sandbox Code Playgroud) 我正在使用Gmaps4rails和Foundation 5.我关注了Gmaps4rails视频教程并且地图没有显示出来.我得到了Uncaught ReferenceError: Gmaps is not defined和违规行是自定义脚本的第一行:
handler = Gmaps.build('Google');
Run Code Online (Sandbox Code Playgroud)
我认为与基金会存在某种冲突,因为我尝试创建一个只有Gmaps4rails并且没有基础的Rails应用程序,一切正常.
我有一个代表学区的多边形,我从NYC Open Data导入.我相信坐标是在epsg投影2263 - nad83/new york long island
我无法将坐标转换为Google地图可用的格式.
这是我从原始shapefile导入多边形的代码:
proj4 = "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
factory = RGeo::Geographic.projected_factory(:projection_proj4 => proj4, :projection_srid => 2263)
RGeo::Shapefile::Reader.open("/Users/dmanaster1/flatiron_school/nycdata/db/source/ES_Zones_2013-2014.shp", :factory => factory.projection_factory) do |file|
file.each do |record|
school_zone = ES_Zone.new
...
school_zone.geometry = record.geometry
school_zone.save
end
file.rewind
end
Run Code Online (Sandbox Code Playgroud)
在我的模型中:
class ES_Zone < ActiveRecord::Base
proj4 = "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
FACTORY = RGeo::Geographic.projected_factory(:projection_proj4 => proj4, :projection_srid => 2263) …Run Code Online (Sandbox Code Playgroud) gmaps4rails ×3
ruby ×3
google-maps ×2
date ×1
formbuilder ×1
forms ×1
geospatial ×1
openlayers ×1
python ×1
rgeo ×1