小编Viz*_*ack的帖子

如何在Ruby类/模块命名空间中翻译模型?

我有一个型号Products :: Car.我该如何翻译其属性?

我已经尝试过了:

activerecord: 
  models:
    products:
      car: "??????????"
  attributes:
    products:
      car:
        owner: "????????"
Run Code Online (Sandbox Code Playgroud)

还有这个:

activerecord: 
  models:
    products_car: "??????????"
  attributes:
    products_car:
      owner: "????????"
Run Code Online (Sandbox Code Playgroud)

但如果我尝试使用Products :: Car.model_name.human,它仍然会说"Car".我的其他翻译工作得很好,语言设置为:ru.

localization namespaces model ruby-on-rails internationalization

42
推荐指数
1
解决办法
8075
查看次数

我在控制器中的帮助方法

我的应用程序应呈现html,以便在用户单击ajax-link时进行回答.

我的控制器:

def create_user
  @user = User.new(params)
  if @user.save
    status = 'success'
    link = link_to_profile(@user) #it's my custom helper in Application_Helper.rb
  else
    status = 'error'
    link = nil
  end

  render :json => {:status => status, :link => link}
end
Run Code Online (Sandbox Code Playgroud)

我的帮手:

  def link_to_profile(user)
    link = link_to(user.login, {:controller => "users", :action => "profile", :id => user.login}, :class => "profile-link")
    return(image_tag("/images/users/profile.png") + " " + link)
  end
Run Code Online (Sandbox Code Playgroud)

我试过这样的方法:

ApplicationController.helpers.link_to_profile(@user)
# It raises: NoMethodError (undefined method `url_for' for nil:NilClass)
Run Code Online (Sandbox Code Playgroud)

和:

class Helper
  include Singleton …
Run Code Online (Sandbox Code Playgroud)

controller ruby-on-rails helper

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

Ruby后台服务

我有一个用Ruby编写的TCPclient.我想在后台使用它.目前它有一个循环:

loop do
end
Run Code Online (Sandbox Code Playgroud)

所以我可以运行一个客户端,它永远有效.

有没有办法作为服务运行,并写一个pid文件,然后我将能够通过pid杀死该进程?

ruby service daemon background tcpclient

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