<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>koell (Koell)</title>
    <link>https://ruby-china.org/koell</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>在使用 Turbo 的情况下 link_to 弹出确认窗口</title>
      <description>&lt;p&gt;Turbo 一般情况下用 button_to 来弹出确认窗口&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= button_to "Delete", post, method: :delete, form: { data: { turbo_confirm: "Are you sure?" } } %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如果需要用 link_to 的话，controller 内需要使用 303 重定向。否则 Turbo 会使用 DELETE method 请求重定向地址。&lt;/p&gt;

&lt;p&gt;View: &lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to "Delete", post, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Controller:&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;redirect_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;status: :see_other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>koell</author>
      <pubDate>Tue, 31 May 2022 00:07:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/42426</link>
      <guid>https://ruby-china.org/topics/42426</guid>
    </item>
    <item>
      <title>Sorbet Compiler: An experimental, ahead-of-time compiler for Ruby</title>
      <description>&lt;p&gt;&lt;a href="https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-compiler" rel="nofollow" target="_blank"&gt;https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-compiler&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;据说比 Ruby 默认实现快 22-170%，但 Stripe 不用 Rails，估计没什么参考意义。&lt;/p&gt;</description>
      <author>koell</author>
      <pubDate>Mon, 02 Aug 2021 00:05:08 +0800</pubDate>
      <link>https://ruby-china.org/topics/41516</link>
      <guid>https://ruby-china.org/topics/41516</guid>
    </item>
    <item>
      <title>Shopify / yjit - Optimizing JIT compiler built inside CRuby</title>
      <description>&lt;p&gt;&lt;a href="https://github.com/Shopify/yjit" rel="nofollow" target="_blank"&gt;https://github.com/Shopify/yjit&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="rvm 用户"&gt;rvm 用户&lt;/h2&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;sqlite3 libsqlite3-dev
git clone https://github.com/Shopify/yjit.git yjit
&lt;span class="nb"&gt;cd &lt;/span&gt;yjit
./autogen.sh
./configure &lt;span class="nt"&gt;--disable-install-doc&lt;/span&gt; &lt;span class="nt"&gt;--disable--install-rdoc&lt;/span&gt; &lt;span class="nt"&gt;--prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;/.rvm/rubies/ruby-yjit
make &lt;span class="nt"&gt;-j16&lt;/span&gt; &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# rvm&lt;/span&gt;
rvm use ruby-yjit &lt;span class="nt"&gt;--create&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>koell</author>
      <pubDate>Mon, 17 May 2021 00:01:54 +0800</pubDate>
      <link>https://ruby-china.org/topics/41268</link>
      <guid>https://ruby-china.org/topics/41268</guid>
    </item>
    <item>
      <title>Rails 如何使用 Session ID 获取 Session 的信息？</title>
      <description>&lt;p&gt;最近在用 rails-api 做一个小项目练手，在做 token 这块的时候，考虑使用 Session ID 做一个简单的认证系统。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;使用 ActionDispatch::Session::CacheStore（将 Session 存在内存里）
&lt;code&gt;ruby
# config/application.rb
config.middleware.use ActionDispatch::Session::CacheStore
config.session_store :cache_store
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;创建 Session
&lt;code&gt;ruby
session[:email] = 'test@example.com'
session[:login] = true
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;获取 Session ID 当成 token 发送到客户端
&lt;code&gt;ruby
render json: [
'token' =&amp;gt; session.id
]
&lt;/code&gt;`&lt;/li&gt;
&lt;li&gt;客户端请求需要权限的 API 时需要在 HTTP Header 或 POST 时带上 Token。&lt;/li&gt;
&lt;li&gt;Rails 使用 Token（Session ID）验证 Session 是否存在和验证用户是否登陆过。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;现在前几步已经实现，而最后一步 Google 查了一下午完全没有头绪。
PHP 可以使用 session_id() 重新恢复会话。&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$token&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;（话说 PHP 的高亮好像坏了……）&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;请问 Rails 有什么类似的方法可以实现使用 Session ID 恢复会话的方式？&lt;/strong&gt;&lt;/p&gt;</description>
      <author>koell</author>
      <pubDate>Thu, 07 Apr 2016 09:56:48 +0800</pubDate>
      <link>https://ruby-china.org/topics/29608</link>
      <guid>https://ruby-china.org/topics/29608</guid>
    </item>
  </channel>
</rss>
