小编Sha*_*fun的帖子

Rails3中的DEPRECATION WARNING for before_create,before_update,before_save,before_destroy

我刚刚将我的应用程序从Rails 2.3升级到3,并且我为before_create,update,save,destroy等获得了一些DEPRECATION WARNINGS.

有谁知道怎么解决这个问题?

这些是我的警告:

DEPRECATION WARNING: Base#before_create has been deprecated, please use Base.before_create :method instead. (called from /Users/macmini/qna/app/models/user.rb:32)
DEPRECATION WARNING: Base#before_update has been deprecated, please use Base.before_update :method instead. (called from /Users/macmini/qna/app/models/user.rb:40)
DEPRECATION WARNING: Base#after_save has been deprecated, please use Base.after_save :method instead. (called from /Users/macmini/qna/app/models/user.rb:50)
DEPRECATION WARNING: Base#before_destroy has been deprecated, please use Base.before_destroy :method instead. (called from /Users/macmini/qna/app/models/user.rb:56)
Run Code Online (Sandbox Code Playgroud)

只是一个before_create的例子:

  def before_create
    self.username.downcase!
    self.salt = User.make_salt(self.username)
    self.hashed_password = User.hash_with_salt(@password, self.salt)
  end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-3

26
推荐指数
1
解决办法
9581
查看次数

使用Qt过滤QFileInfoList文件

我有一个QFileInfoList(列表),其中包含有关目录及其文件的信息

QFileInfoList list = directory.entryInfoList();
Run Code Online (Sandbox Code Playgroud)

如何应用过滤器来删除除图像文件(jpg,gif,png等)之外的所有内容?

这是一个简单的foreach循环,只删除不是文件的所有内容

foreach (QFileInfo f, list){
        if (!f.isFile()){
        list.removeOne(f);
        }
Run Code Online (Sandbox Code Playgroud)

如何应用过滤器来删除除图像文件(jpg,gif,png等)之外的所有内容?

c++ qt qt4

7
推荐指数
1
解决办法
1万
查看次数

Rails在显示之前检查对象存在的方式

我想找到一个很好的方法来检查我的对象,然后我在视图中显示它们,所以我不会得到错误.

这是我的控制者

 @user = User.find_by_username(params[:username])
 @profile = @user.profile 
 @questions = @user.questions
Run Code Online (Sandbox Code Playgroud)

这是我的观点

 <% unless @profile.blank? %><%= link_to 'Edit Profile', :controller => 'profiles', :action => 'edit' %><% end %>


     <% unless @user.blank? %>
        Username:<%= @user.username %><br />
    Member Since:<%= @user.created_at.strftime("%d %B %Y")  %><br />
    <% end %>

  <% unless @profile.blank? %>
    First Name: <%= @profile.first_name %><br />
    Last Name: <%= @profile.last_name %><br /><br />
    About: <%= @profile.body %><br /><br />
    Location: <%= @profile.location %><br />
    Birthday: <%= @profile.birthday.strftime("%d %B %Y") %><br …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-3

5
推荐指数
2
解决办法
2万
查看次数

使用QSettings存储qt应用程序的设置

您好我已经使用qt创建了一个应用程序,我设法使用QSettings保存了一些设置.

void DoneIt::writeSettings()
{
    QSettings settings("mycompany", "RightDoneIt");
    settings.beginGroup("DoneIt");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    settings.endGroup();
}

void DoneIt::readSettings()
{
    QSettings settings("mycompany", "RightDoneIt");
    settings.beginGroup("DoneIT");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    settings.endGroup();
}
Run Code Online (Sandbox Code Playgroud)

这与窗口位置和大小一起工作正常.我使用qt的设计者在我的应用程序中添加了一些小部件,我也希望保存它们的状态.

我的一个小工具是一个单选按钮,我称之为radioButtonbnw

如何保存其状态(已选中或未选中)?

什么是最佳做法?

c++ qt qt4 qsettings

5
推荐指数
1
解决办法
5551
查看次数

Rails Flash通知不在url上,而是在object中

在我的用户控制器/模型中,我正在创建一个用户.当我重定向到用户

format.html { redirect_to(@user, :notice => 'You have successfully registered!') }
Run Code Online (Sandbox Code Playgroud)

我的页面上显示了一个很好的通知

当我尝试重定向到没有对象的不同控制器

 format.html { redirect_to(:controller => 'profiles', :action => 'index', :notice => 'You have successfully registered!') }
Run Code Online (Sandbox Code Playgroud)

我在网址上收到通知,但没有显示在我的网页上.

profile?notice=You+have+successfully+registered%21
Run Code Online (Sandbox Code Playgroud)

有没有办法将通知放入某个对象并将其显示在我的页面上?

ruby-on-rails ruby-on-rails-3

4
推荐指数
1
解决办法
1287
查看次数

Google Analytics上的多个自定义变量

我正在尝试在Google Analytics上测试6个自定义变量.

当我进入高级细分时,我只能看到最后一个变量的访问.如何使其余的自定义变量起作用?

我不知道是否必须将_trackPageview放在一个以上,所以我尝试将它放在我的第五个频道之后它仍然无效.

这是我的代码:

<script type="text/javascript">

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(["_setCustomVar", 1, "Channel", "One", 3]); 
_gaq.push(["_setCustomVar", 1, "Channel", "Three", 1]); 
_gaq.push(["_setCustomVar", 1, "Channel", "Four", 1]); 
_gaq.push(["_setCustomVar", 1, "Channel", "Five", 2]); 
_gaq.push(['_trackPageview']);  
_gaq.push(["_setCustomVar", 1, "Channel", "Six", 2]);
 _gaq.push(['_trackPageview']);  

  (function() {

    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

  })();

</script>
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄这个吗?

如何才能使多个自定义变量起作用?

谢谢你这么!

google-analytics

3
推荐指数
1
解决办法
3537
查看次数

使用 Authlib 和 Flask 获取和存储刷新令牌

我正在使用 authlib https://github.com/lepture/authlib获取用户对其数据的身份验证,因此每日离线调度程序可以代表用户下载一些数据。

我首先注册客户端:

google = oauth.register(
    'google',
    client_id = '***',
    client_secret = '***',
    access_token_url = "https://www.googleapis.com/oauth2/v4/token", 
    access_token_params = None,
    authorize_url = "https://accounts.google.com/o/oauth2/v2/auth",
    authorize_params = None,
    api_base_url = 'https://googleapis.com/oauth2/v1/',
    client_kwargs={'scope': 'https://www.googleapis.com/auth/doubleclickbidmanager'}
)
Run Code Online (Sandbox Code Playgroud)

在稍后阶段,我使用以下方法检索令牌:

token = oauth.google.authorize_access_token()
Run Code Online (Sandbox Code Playgroud)

当我打印令牌时,我看到 Google 没有返回我需要存储在数据库中以供离线使用的刷新令牌:

{'access_token': '***', 'expires_in': 3599, 'scope': 'https://www.googleapis.com/auth/doubleclickbidmanager', 'token_type': 'Bearer', 'expires_at': 1591750317}
Run Code Online (Sandbox Code Playgroud)

我可以更改使用 access_type = offline 注册客户端的方式,以便让 Google 知道我也需要刷新令牌吗?如何获取和存储刷新令牌?

python flask oauth-2.0 authlib requests-oauthlib

3
推荐指数
1
解决办法
675
查看次数

类型为'void(ClassName ::)(QString&)'的参数与'void(ClassName ::*)(QString&)'不匹配

我试图使用Qt的qtconcurrentmap来处理一些图像,我收到以下错误

argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)
Run Code Online (Sandbox Code Playgroud)

我也来了

/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:: 
In member function 'bool QtConcurrent::MapKernel<Iterator, MapFunctor>::runIteration(Iterator, int, void*) 
[with Iterator = QList<QString>::iterator, MapFunctor = void (ClassName::*)(QString&)]':


/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:73: 
error: must use '.*' or '->*' to call pointer-to-member function in 
'((QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>*)this)->QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>::map (...)'
Run Code Online (Sandbox Code Playgroud)

这是我的代码

void ClassName::processImage(QString &f)
{

    Image image;
        image.read(qPrintable(f));
        try {
            //Apply effects on an Image
        } catch ( Magick::Exception & error) {
            // Displaying any possible errors on the text browser …
Run Code Online (Sandbox Code Playgroud)

c++ qt qt4

0
推荐指数
1
解决办法
1565
查看次数

正则表达式扫描html并从元刷新标记返回URL

我正在尝试扫描html内容以查找源代码是否包含元刷新标记以获取URL.

以下是我见过的meta http-equiv ="refresh"标签的一些案例

<META HTTP-EQUIV="refresh" CONTENT="0;URL=https://example.de/">
<META HTTP-EQUIV="refresh" CONTENT="0; URL=https://example.com/test">
<meta http-equiv="refresh" content='0;URL=/test' />
<meta http-equiv='refresh' content='0; URL=/test' />
Run Code Online (Sandbox Code Playgroud)

这是我想出的

$url = response.body.scan(/(CONTENT="0;URL=)(.*?)(">)/)
Run Code Online (Sandbox Code Playgroud)

/(CONTENT="0;URL=)(.*?)(">)/将首次正常工作,没有空格; 和URL不是其他任何东西.

有人可以帮助我使用适用于所有4种情况的正则表达式吗?

ruby regex html-parsing ruby-on-rails-4

0
推荐指数
1
解决办法
483
查看次数