当我调用输出长度大于终端窗口长度的方法时,在输出结束时返回突出显示的(END)(见图).我怎么能逃脱这个?
我想做两件事:
1)更改默认的"编辑用户表单" - 随设备提供 - 删除"密码"并允许更新其他字段而无需输入密码,即删除密码的默认验证.
2)创建一个单独的表单来更改密码
我有一切工作,只有一个问题,在单独的表格更新密码,我已经包括一个当前密码的字段.使用表单时,没有对当前密码进行验证,所以我改变了
@user.update_attributes(params[:user])
Run Code Online (Sandbox Code Playgroud)
至
@user.update_with_password(params[:user])
Run Code Online (Sandbox Code Playgroud)
这有效,但它提出了另一个问题.返回主表单中除了密码之外的所有其他详细信息,表单现在要求"当前密码".如果没有验证主表单上调用的当前密码,我怎样才能实现这一目的?
这是我的注册控制器:
def update
@user = User.find(current_user.id)
if @user.update_attributes(params[:user])
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
clean_up_passwords(resource)
respond_with_navigational(resource) do
if params[:change_password] # or flash[:change_password]
render :change_password
else
render :edit
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢!
我找到了解决问题的方法(虽然非常混乱):
def update
@user = User.find(current_user.id)
if params[:user][:password].blank?
if @user.update_attributes(params[:user])
set_flash_message :notice, :updated
# Sign in the user …
Run Code Online (Sandbox Code Playgroud) 我正在为Rails 3/Active Record项目寻找一个相对简单的状态机插件.
我做了一些研究,并提出了以下插件:
但它们看起来都非常相似,所以我很想知道是否有人有任何实际经验.
谢谢!
ruby ruby-on-rails state-machine ruby-on-rails-plugins ruby-on-rails-3
我已经开始学习rails了,我想在评论中添加ajax
应使用Ajax添加注释
你能帮忙或链接到一个例子吗?
这是我的config.rb:
resources :posts do
resources :comments
end
Run Code Online (Sandbox Code Playgroud)
在post/show.html.erb中
<p><%= @post.title %></p>
<h2>Comments:</h2>
<div id='com'>
<%= render @post.comments %>
</div>
<h2>Add a comment:</h2>
<%= render "comments/form" %>
Run Code Online (Sandbox Code Playgroud)
在view/comments/_comment.html.erb中:
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<%= link_to "Del", [comment.post, comment], :confirm => 'Are you sure?', :method => :delete %>
<hr>
Run Code Online (Sandbox Code Playgroud)
在comments/form.html.erb中
<%= form_for([@post, @post.comments.build], remote: true) do |f| %>
.
.
.
Run Code Online (Sandbox Code Playgroud)
在comments_controller中:
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment …
Run Code Online (Sandbox Code Playgroud) 既然Devise已从数据库中删除了:confirmation_token,我该如何在rspec中返回设计确认令牌?
我试图通过手动访问带有确认令牌的user_confirmation路径来测试可确认模块.我怎样才能做到这一点?
我正试图用facebook/twitter登录,然后跟着这个railscast
我已将以下内容添加到我的config/initializers/devise.rb中(我在其中输入了我的消费者密钥和Twitter提供的消费者密钥).
config.omniauth :twitter, ENV["TWITTER_CONSUMER_KEY"], ENV["TWITTER_CONSUMER_SECRET"]
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中添加":omniauthable"后,以下内容为#<#:0x007febf67af938>生成此错误"未定义的局部变量或方法`resource_class'"
- if devise_mapping.omniauthable?
- resource_class.omniauth_providers.each do |provider|
Run Code Online (Sandbox Code Playgroud) 是否可以动态创建以下2d数组:
[[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2], [4, 1], [4, 2]]
Run Code Online (Sandbox Code Playgroud)
例如.
(1..4).to_a
#=> [1, 2, 3, 4]
(1..2).to_a
#=> [1, 2]
Run Code Online (Sandbox Code Playgroud)
以某种方式结合这个?
如何简化以下if语句以消除重复?
if user.name == "john" && user.age > 10 or user.name == "wendy" && user.age > 10 or user.name == "mary" && user.age > 10
Run Code Online (Sandbox Code Playgroud)
谢谢!
发出刷新请求和清空elasticsearch的缓存之间有什么区别?重新启动elasticsearch是否实现了这些?
背景:当用户点击一个button
其类之间切换class1
并且class2
该数据被经由提交AJAX
.要确认此数据已保存,服务器将使用js
(更新按钮HTML
)进行响应.
问题:如果用户按下按钮的速度快于服务器可以响应的速度(即快速按下按钮),则一旦服务器响应实际到达,按钮将来回切换:
class2
通过js(AJAX提交)class1
通过js(AJAX提交)class2
class1
如果制作一个新的请求,如何取消ajax请求?
$('.button').click(function() {
$('this').toggleClass('class1 class2')
// submit ajax request
$.ajax({
url: '/update_link'
})
});
Run Code Online (Sandbox Code Playgroud)