我正在使用rails 3.0.9并设计用于身份验证.现在我正在尝试使用单表继承,因为我需要使用多态,所以我有两个类:UserType1和UserType2,它继承自User类.我根据用户的类型正确地需要Devise实例current_user.
例如,
class User < ActiveRecord::Base
#devise and other user logic
end
class UserType1 < User
def get_some_attribute
return "Hello, my type is UserType1"
end
end
class UserType2 < User
def get_some_attribute
return "Hello, my type is UserType2"
end
end
In controller
class MyController < ApplicationController
def action
@message = current_user.get_some_attribute #depending the type using polymorphism
render :my_view
end
end
Run Code Online (Sandbox Code Playgroud) ruby-on-rails single-table-inheritance devise ruby-on-rails-3
我正在开发一个Ruby On Rails 2.3.8应用程序,我想知道如何remote_form_for在用户按下textarea中的ENTER键时提交表单.
这是表单代码:
<% remote_form_for :post, PostComment.new, :url => save_outside_comment_path(post_id), :html => { :method => :put} do |f| %>
<%= f.text_area :comment, :rows => 1, :id => "txtOutsideComment_#{post_id}", :class => "new-reply-text" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是执行提交的jQuery函数,但不是AJAX:
jQuery('.new-reply-text').keypress(function(e) {
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault();
this.form.submit();
}
});
Run Code Online (Sandbox Code Playgroud)
我已经从我的控制器进行了页面更新,我是否不想指定任何语法,例如success:来自这个jQuery函数.我只是想让它提交remote_form_for使用AJAX.