我正在尝试在rails 3上安装mogli gem(http://github.com/mmangino/mogli)并且遇到配置问题.我有否使用Rails 2的经验.
对于Rails 2
Add config.gem "mogli" to environment.rb
Run Code Online (Sandbox Code Playgroud)
对于Rails 3,我将以下内容添加到gemfile中.
gem 'mogli'
Run Code Online (Sandbox Code Playgroud)
对于Rails 2,路由
map.resource :oauth, :controller=>"oauth"
map.root :controller=>"oauth"
map.oauth_callback "/oauth/create", :controller=>"oauth", :action=>"create"
Run Code Online (Sandbox Code Playgroud)
对于Rails 3,我补充道
resources :oauth
root :to => "oauth#index"
Run Code Online (Sandbox Code Playgroud)
我不知道如何在Rails 3中表示map.oauth_callback.
谢谢
我有一个应用程序需要发送用户事件邀请.当用户邀请朋友(用户)参加活动时,如果尚不存在将用户连接到该事件的新记录,则创建该记录.我的模型由user,event和events_user组成.
class Event
def invite(user_id, *args)
user_id.each do |u|
e = EventsUser.find_or_create_by_event_id_and_user_id(self.id, u)
e.save!
end
end
end
Run Code Online (Sandbox Code Playgroud)
用法
Event.first.invite([1,2,3])
Run Code Online (Sandbox Code Playgroud)
我不认为以上是完成任务的最有效方法.我设想了一种类似的方法
Model.find_or_create_all_by_event_id_and_user_id
Run Code Online (Sandbox Code Playgroud)
但是一个不存在.
没有验证的模型
class User
has_many :events_users
has_many :events
end
class EventsUser
belongs_to :events
belongs_to :users
end
class Event
has_many :events_users
has_many :users, :through => :events_users
end
Run Code Online (Sandbox Code Playgroud) 我有一个jquery .each循环,它从json请求中检索具有特定类的页面上所有元素的远程数据.一组元素是一组li标签,我希望在使用li远程信息更新元素后使用另一个函数对其进行排序.
在.each循环之后传递sort函数不对列表进行排序,因为项目尚未从json请求中完成加载.分拣工作.如果我在排序函数传递作为.complete对的getJSON请求回调,但我只希望排序整个名单运行一次,而不是每个项目.
fetch_remote_data(function(){sort_list_by_name();});
function fetch_remote_data(f){
jQuery('.fetching').each(function(){
var oj = this;
var kind = this.getAttribute('data-kind');
var url = "http://something.com"
jQuery.getJSON(url, function(json){
$(oj).text(json[kind]);
$(oj).toggleClass('fetching');
});
});
if (typeof f == 'function') f();
};
Run Code Online (Sandbox Code Playgroud)
有什么建议?