<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>w353284782 (毛子)</title>
    <link>https://ruby-china.org/w353284782</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>关于将 session 保存到数据库中备份时的问题</title>
      <description>&lt;p&gt;小弟最近遇到一个麻烦就是按照网上说的现在的 rails 中的 session 不能超过 4KB 不然会抛出错误而我项目中 session 保存的东西较多 往往超过 4KB 这时就需要将 session 保存到数据库中。我是按照一下方式进行的：
修改 initializers\session_store.rb 加入
&lt;code&gt;
Test::Application.config.session_store :active_record_store
&lt;/code&gt;
修改 initializers\secret_token.rb 加入
&lt;code&gt;
Test::Application.config.secret_token = '479db880dd2cak2f78618ba03c0dcfa334f2e798e140f5f90e459e819aa9070c2177a7425e8ee521eaae72df2b11090f920655deabdf10aa53f77fa7729868e8'
&lt;/code&gt;
这样能够实现功能但是在数据库备份的时候使用的 mysql 自带的命令
&lt;code&gt;
mysqldump -uusername -ppassword --opt databasename table1 table2 &amp;gt; backupfile.sql
&lt;/code&gt;
备份成功后会清空 session 这是为什么呢？网上找了很久都不清楚有什么办法能解决吗？&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Fri, 26 Oct 2012 11:33:37 +0800</pubDate>
      <link>https://ruby-china.org/topics/6336</link>
      <guid>https://ruby-china.org/topics/6336</guid>
    </item>
    <item>
      <title>关于将 session 保存到数据库中备份时的问题</title>
      <description>&lt;p&gt;小弟最近遇到一个麻烦就是按照网上说的现在的 rails 中的 session 不能超过 4KB 不然会抛出错误而我项目中 session 保存的东西较多 往往超过 4KB 这时就需要将 session 保存到数据库中。我是按照一下方式进行的：
修改 initializers\session_store.rb 加入
&lt;code&gt;
Test::Application.config.session_store :active_record_store
&lt;/code&gt;
修改 initializers\secret_token.rb 加入
&lt;code&gt;
Test::Application.config.secret_token = '479db880dd2cak2f78618ba03c0dcfa334f2e798e140f5f90e459e819aa9070c2177a7425e8ee521eaae72df2b11090f920655deabdf10aa53f77fa7729868e8'
&lt;/code&gt;
这样能够实现功能但是在数据库备份的时候使用的 mysql 自带的命令
&lt;code&gt;
mysqldump -uusername -ppassword --opt databasename table1 table2 &amp;gt; backupfile.sql
&lt;/code&gt;
备份成功后会清空 session 这是为什么呢？网上找了很久都不清楚有什么办法能解决吗？&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Fri, 26 Oct 2012 10:57:05 +0800</pubDate>
      <link>https://ruby-china.org/topics/6334</link>
      <guid>https://ruby-china.org/topics/6334</guid>
    </item>
    <item>
      <title>关于 TwitterAPI：/1.1/statuses/update_with_media.json</title>
      <description>&lt;p&gt;小弟最近有需求是需要向 Twitter 上发布推文中包含图片，
看了下这个 Twitter 的
&lt;code&gt;https://api.twitter.com/1.1/statuses/update_with_media.json&lt;/code&gt;
这个 API 能满足要求。
但是它上传的应该是一个二进制的流，这块又不是很懂，不知道从哪下手，不知道
各位大哥有没有什么插件能满足或者有例子就更好了！&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Tue, 23 Oct 2012 13:30:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/6259</link>
      <guid>https://ruby-china.org/topics/6259</guid>
    </item>
    <item>
      <title>虚拟主机服务商的选择</title>
      <description>&lt;p&gt;小弟想问一下，我找的几个国外服务商&lt;/p&gt;

&lt;p&gt;1.Godaddy 
2.hostmonster
3.BlueHost
4.LunarPages&lt;/p&gt;

&lt;p&gt;这几个都是支持 ror 和 mysql 口碑不错反映也不错的服务商。
在上面 4 个的优缺点是什么！最好选择什么呢？&lt;/p&gt;

&lt;p&gt;我主要是做的聊天形式服务器&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Fri, 31 Aug 2012 09:32:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/5272</link>
      <guid>https://ruby-china.org/topics/5272</guid>
    </item>
    <item>
      <title>关于 join 的问题</title>
      <description>&lt;p&gt;小弟最近有遇见问题了，具体如下：&lt;/p&gt;

&lt;p&gt;我有两张表 message（消息表）user（用户表）
message 表中有 3 个字段 user1_id（发信息用户 ID）user2_id（收信息用户 ID）info（内容）
user 表 中一个 name（用户名）字段
请问一下在 rails 中用户 joins 能否将 2 张表连接起来 查询 message 的时候将 user 的名称也能查出来？&lt;/p&gt;

&lt;p&gt;还有就是 我用过 find_by_sql 如果是是&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Message.find_by_sql("select users.name from users INNER JOIN messages ON messages.users1_id = users.id") 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样的话查出来的全是 Message 的空对象！&lt;/p&gt;

&lt;p&gt;SOS！&lt;img title=":sob:" alt="😭" src="https://twemoji.ruby-china.com/2/svg/1f62d.svg" class="twemoji"&gt;&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Thu, 30 Aug 2012 14:05:33 +0800</pubDate>
      <link>https://ruby-china.org/topics/5251</link>
      <guid>https://ruby-china.org/topics/5251</guid>
    </item>
    <item>
      <title>关于 rails 中子查询的问题</title>
      <description>&lt;p&gt;我想问一下像下列 sql 语句在 rails 中除了 find_by_sql 方法外 能用什么其他的方法组合&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select * from Programs as a where name='0' and created_at = (select max(b.created_at) from Programs as b where user_id = a.user_id ) 
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>w353284782</author>
      <pubDate>Fri, 24 Aug 2012 10:13:49 +0800</pubDate>
      <link>https://ruby-china.org/topics/5122</link>
      <guid>https://ruby-china.org/topics/5122</guid>
    </item>
    <item>
      <title>ruby 怎么将 unicode 转换成汉字</title>
      <description>&lt;p&gt;比如\u770B\u89C1 怎么将他变成汉字输出啊
在网上查的
Iconv.conv("utf-8","utf-16",str) 这个方法貌似不行啊&lt;/p&gt;

&lt;p&gt;完整代码是&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#encoding: utf-8
english_map=[]
china_map=[]
index=0
puts "系统初始化中,请等待......"
File.open("text.txt","r:utf-8").each do |i|
  english_map[index] = i.to_s.scan(/([a-zA-Z]+)=/)
  china_map[index] =i.to_s.scan(/=([\u4E00-\u9FA5]+)/)
  index+=1
end


def run_topic(result, num, english_map, china_map)
  if result==china_map[num]
    puts "正确!"
    puts "任意键继续。"
    temp=gets
  else
    puts "不正确!"
    puts "输入1查看正确意思，输入2再次作答,输入其他换一题。"
    temp=gets
    if temp.to_i == 1
      puts "正确答案为：#{china_map[num]}"
    elsif temp.to_i == 2
      run_topic(input_result(num, english_map), num, english_map, china_map)
    end
  end
end

def  input_result(num, english_map)
  puts "请输入 #{english_map[num]} 汉语意思:"
  return result=gets
end
puts "初始化完毕。"

while true
  num = rand(english_map.length-1)
  result = input_result(num, english_map)
  run_topic(result, num, english_map, china_map)
end

text.txt内容为：
feel=感觉
fill=填充
leap=跳
lip=嘴唇
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;等等&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Fri, 25 May 2012 11:39:08 +0800</pubDate>
      <link>https://ruby-china.org/topics/3490</link>
      <guid>https://ruby-china.org/topics/3490</guid>
    </item>
    <item>
      <title>一个路由的问题！</title>
      <description>&lt;p&gt;大家好！小弟遇到一点问题，望大家能帮忙解决下。&lt;/p&gt;

&lt;p&gt;我的路由是这么写的：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :homes do
  resources :articles
    resources :photo_albums do
      resources :photos
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但是调用 home_photo_album_photos_path GET 请求方式按照 rake routes 的显示应该调用 photos#index 但是却显示&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Routing Error

No route matches {:controller=&amp;gt;"photos"}

Try running rake routes for more information on available routes. 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;的错误。说没有 photos 的 controller &lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Mon, 14 May 2012 13:57:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/3263</link>
      <guid>https://ruby-china.org/topics/3263</guid>
    </item>
    <item>
      <title>Rails3 中的表单 AJAX 提交怎么写啊！</title>
      <description>&lt;p&gt;大家好！我是一个新手 ruby 程序员 希望大家多多指教！&lt;/p&gt;

&lt;p&gt;我是怎么写 但是不行啊 
View:
 &amp;lt;%=form_tag "/ajax/login", remote: true, method: 'post'  do%&amp;gt;
        用户名：&amp;lt;%=text_field_tag 'username' %&amp;gt;
        密&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;码：&amp;lt;%=password_field_tag 'password'%&amp;gt;
        &amp;lt;%=submit_tag '登录'%&amp;gt;
    &amp;lt;%end%&amp;gt;&lt;/p&gt;

&lt;p&gt;Controller:
  def login
    user=User.verification_return_user(params[:username], params[:password])
    &lt;a href="/result" class="user-mention" title="@result"&gt;&lt;i&gt;@&lt;/i&gt;result&lt;/a&gt;=false
    if user
      session[:user]=user
      &lt;a href="/result" class="user-mention" title="@result"&gt;&lt;i&gt;@&lt;/i&gt;result&lt;/a&gt;=true
    end
  end&lt;/p&gt;

&lt;p&gt;提交上去输出的是这个：&lt;/p&gt;

&lt;p&gt;Started POST "/ajax/login" for 127.0.0.1 at 2012-05-10 09:06:38 +0800
Processing by AjaxController#login as JS
  Parameters: {"utf8"=&amp;gt;"✓", "authenticity_token"=&amp;gt;"q/SRVvcyjF5l1ZhSfAs09SLb7fb4YH5VUNWpz9pOqCo=", "username"=&amp;gt;"", "password"=&amp;gt;"[FILTERED]", "commit"=&amp;gt;"登录"}
  User Load (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."username" = '' LIMIT 1
  Rendered ajax/login.html.erb within layouts/application (0.0ms)
Completed 200 OK in 91ms (Views: 29.0ms | ActiveRecord: 0.0ms)&lt;/p&gt;

&lt;p&gt;但是页面什么反映也没有。。&lt;/p&gt;</description>
      <author>w353284782</author>
      <pubDate>Thu, 10 May 2012 09:08:02 +0800</pubDate>
      <link>https://ruby-china.org/topics/3183</link>
      <guid>https://ruby-china.org/topics/3183</guid>
    </item>
  </channel>
</rss>
