Rails - ActionController::Parameters 到字符串 [英] Rails - ActionController::Parameters to string

查看:36
本文介绍了Rails - ActionController::Parameters 到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个参数,我得到了一个这样的

There are two params and am getting a single one like that

v = (params.require(:service).permit(:title))

这个 v 有一个这样的值 {"title"=>"test,kil"} 我想得到一个字符串右侧的值,但都是徒劳的.之后我试图强加的概念是 @test="test,kil"

This v has a value like this {"title"=>"test,kil"} and I want to get the value of right side to a string, but all in vain. The concept am trying to impose after that i will have @test= "test,kil"

任何帮助都会很棒.我是 Rails 的新手.

Anyhelp will be great full. am a newbie to Rails.

推荐答案

params 在 Rails 中只是一个哈希(很好).

params in Rails is just a Hash (well kind of).

要在 Ruby 中访问哈希值,请使用方括号语法:

To access the values of a hash in Ruby you use the square bracket syntax:

v = params.require(:service).permit(:title)
@test = v['title']

Rails 中的参数是一种特殊的哈希类型,称为 HashWithIndifferentAccess.所以我们可以同时使用 v['title']v[:title].

Params in Rails are a kind a special hash type called HashWithIndifferentAccess. So we can do both v['title'] or v[:title].

这篇关于Rails - ActionController::Parameters 到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆