百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

phrasing

> 编程语言
开源

为您的 Ruby on Rails 应用程序在线编辑短语!

544 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

为您的 Ruby on Rails 应用程序在线编辑短语!

Phrasing!

Phrasing is a gem for live editing phrases (copy) on websites.

Installation

Include the gem in your Gemfile

ruby
gem "phrasing"

Bundle the Gemfile

bash
bundle install

Run the install script which will create a migration file and a config file.

bash
rails generate phrasing

Migrate your database

bash
rake db:migrate

Setup

The rake task will also generate phrasing_helper.rb in your app/helpers folder. Here you will need to implement the can_edit_phrases? method. Use this to hook-up your existing user authentication system to work with Phrasing.

For example:

ruby
module PhrasingHelper
  def can_edit_phrases?
    current_user.is_admin?
  end
end

Include the phrasing html initializer right below the `` tag in your application layout file.

Include the required javascript files:

javascript
//= require phrasing

Include the required javascript files:

javascript
//= require jquery
//= require jquery_ujs
//= require phrasing

Include the required stylesheet file:

css
*= require phrasing

How to use phrasing?

You can start adding new phrases by simply adding them in your view file:

Aside from editing phrases (basically, Rails translations) you can also edit model attributes inline. Use the same phrase method, with the first attribute being the record in question, and the second one the attribute you wish to make editable:

In the above example, @post is the record with a title attribute.

Security

Since Phrasing can be used to update any attribute in any table (using the model_phrase method), special care must be taken into consideration from a security standpoint.

By default, Phrasing doesn't allow updating of any attribute apart from PhrasingPhrase.value. To be able to work with other attributes, you need to whitelist them.

In the config/initializers/phrasing.rb file you can whitelist your model attributes like this:

ruby
config.white_list = ["Post.title", "Post.body"]

or you can whitelist all of them (not recommended) with:

ruby
config.allow_update_on_all_models_and_attributes = true

Turbolinks

If you're using Turbolinks make sure the phrasing gem is required after it:

javascript
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require phrasing

Phrasing Appearance

The phrase view helper can take the options hash as the last parameter. Features:

ruby
url: custom_url # point Phrasing to other actions in other controllers
inverse: true # change the hovered background and underline colors to better fit darker backgrounds
class: custom_class # add custom CSS classes to your phrases to change the appearance of phrases in your application
scope: 'homepage.footer' # add scopes just like you would w/ I18.n. If the first argument is 'test', than the key would be 'homepage.footer.test'

Credits

Phrasing is maintained and sponsored by Infinum.

Phrasing leverages parts of Copycat and ZenPen.

License

Phrasing is Copyright © 2013 Infinum. It is free software, and may be redistributed under the terms specified in the LICENSE file.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyopen-sourceruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言