我有一个简单的查询:
SELECT u_name AS user_name FROM users WHERE user_name = "john";
Run Code Online (Sandbox Code Playgroud)
我得到Unknown Column 'user_name' in where clause.'user_name'即使之后,我还不能在声明的其他部分提及select 'u_name as user_name'吗?
我有一个带有输入字段/标签等的表单.如何在字段旁边显示错误消息?而不是在顶部聚集在一起?
我正在使用设计,导轨3
我把它放在表格的顶部:
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
- if resource.errors.any?
#errorExplanation
%h2
= pluralize(resource.errors.count, "error")
prevented this user from being saved:
%ul
- resource.errors.full_messages.each do |msg|
%li
= msg
Run Code Online (Sandbox Code Playgroud) 这是我最初的迁移:
class CreateUsers < ActiveRecord::Migration
def self.up
ActiveRecord::Base.transaction do
create_table "users", :force => true do |t|
t.string :login, :limit => 40
t.string :name, :limit => 100, :default => '', :null => true
t.string :email, :limit => 100
t.string :crypted_password, :limit => 40
t.string :salt, :limit => 40
t.string :remember_token, :limit => 40
t.datetime :remember_token_expires_at
t.string :activation_code, :limit => 40
t.datetime :activated_at, :datetime
t.string :state, :null => :no, :default => 'passive'
t.datetime :deleted_at
t.integer :occupation_id, :null => :yes
t.datetime :paid_up_to_date, :date …Run Code Online (Sandbox Code Playgroud) 我正在设置设计,需要能够使用设计助手.当我添加 before_filter :authenticate_user!到应用程序控制器时,我收到以下错误undefined method 'authenticate_user!' for #<HomeController:*>
它不是直接存在于我的家庭控制器中,而是从应用程序控制器继承,如果skip_before_filter :authenticate_user!我在家中(或任何控制器)使用并尝试访问该页面,我会收到以下错误.
undefined method `user_signed_in?' for #<#<Class *>
Run Code Online (Sandbox Code Playgroud)
它打破了调用它的layouts/application.html.erb文件中的行.任何助手都会发生同样的事情.但是,当我加载rails控制台并输入$LOAD_PATH.dup包含的输出时,它看起来好像根本没有被加载
"/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/controllers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/helpers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/mailers"
Run Code Online (Sandbox Code Playgroud)
所以看起来它们确实应该由rails加载.
这是我的应用程序控制器
class ApplicationController <ActionController :: Base
helper:all
#include all helper,protect_from_forgery一直
包括ActionView :: Helpers :: NumberHelper
before_filter:authenticate_user!结束
我在安装设备后重新启动了服务器,并且多次尝试不同的尝试来解决问题.如果需要更多文件或信息,请告诉我.非常感谢你提前.
编辑:我的user.rb文件被要求显示我确实安装了devise
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:encryptable, :encryptor => :restful_authentication_sha1
# Setup accessible …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套的资源附件,我想创建一个link_to销毁/删除附件.这就是我所拥有的,但它是作为GET而不是PUT发布的:
<%= link_to "Delete Attachment", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete, :action => "destroy" %>
Run Code Online (Sandbox Code Playgroud)
想法?谢谢!
我试图对ints 的Python列表进行排序,然后使用该.pop()函数返回最高的一个.我尝试过以不同的方式编写方法:
def LongestPath(T):
paths = [Ancestors(T,x) for x in OrdLeaves(T)]
#^ Creating a lists of lists of ints, this part works
result =[len(y) for y in paths ]
#^ Creating a list of ints where each int is a length of the a list in paths
result = result.sort()
#^meant to sort the result
return result.pop()
#^meant to return the largest int in the list (the last one)
Run Code Online (Sandbox Code Playgroud)
我也试过了
def LongestPath(T):
return[len(y) for y in …Run Code Online (Sandbox Code Playgroud) 我有一个带有编辑模式的rails应用程序.提交功能有效,但关闭按钮不起作用.
Edit.js.erb:
$("#modal-window").html("<%= escape_javascript(render 'users/edit') %>");
Run Code Online (Sandbox Code Playgroud)
_edit.html.erb
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<%= form_for @user,url: root_path,:method => :GET do |f|%>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<%# submit_tag 'Cancel', :type => :reset, :class => "btn btn-danger", "data-dismiss" => "modal", "aria-hidden" => "true" %>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
视图中的线条打开并容纳模态
<%= link_to …Run Code Online (Sandbox Code Playgroud) 有什么办法来设定值比如哈希值<,>,%,+,等?我想创建一个接受一个int数组的方法,以及一个带参数的哈希.
在下面的方法中array是要过滤的数组,并且hash是参数.这个想法是删除任何小于min或大于的数字max.
def range_filter(array, hash)
checker={min=> <, ,max => >} # this is NOT working code, this the line I am curious about
checker.each_key {|key| array.delete_if {|x| x checker[key] args[key] }
array.each{|num| puts num}
end
Run Code Online (Sandbox Code Playgroud)
期望的结果将是
array=[1, 25, 15, 7, 50]
filter={min=> 10, max=> 30}
range_filter(array, filter)
# => 25
# => 15
Run Code Online (Sandbox Code Playgroud) 我正在使用postgres支持的全文搜索,我安装了acts_as_tsearch插件并且它运行成功,但是当我稍后尝试它时发现了一个错误
runtimeError:ERROR C42883函数ts_rank_cd(text,tsquery)不存在HNo函数匹配给定的名称和参数类型.您可能需要添加显式类型
我如何以绝对div为中心?
<div class="photoWindow">min width 600 px, absolute</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的
var widthScreen = $(window).width();
$('.photoWindow').css({'margin-left': widthScreen / 2 - widthScreen, 'left':'50%'});
Run Code Online (Sandbox Code Playgroud)
但是,这并不是div的中心.