首页 \ 问答 \ 在rails生成器中检索生成器名称(Retrieving generator name in a rails generator)

在rails生成器中检索生成器名称(Retrieving generator name in a rails generator)

我正在尝试设置一个rails生成器,我的第一个,在过去的两个小时里,我一直坚持一些非常简单的东西 - 如何让用户输入生成器的名称。 这是在应用程序而不是宝石。

所以在下面的例子中 - 我如何让'Foo'在生成器代码上打印?

rails g block Foo

class BlockGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  puts #Foo (file name)#
end

我尝试过使用NamedBase和base生成器以及我能找到的每种方法。

任何帮助将不胜感激!

#编辑
$ rails g block Foo

class BlockGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)
  argument :generator_name, type: :string

  puts #Foo (file name)#
end

#result

block
No value provided for required arguments 'generator_name'


$ rails generate block :generator_name => testing

 #result

 is empty, nothing is printed to the console. 

I'm trying to set up a rails generator, my first one, and for the past two hours I've been stuck on something really simple - How do I get the users inputed name for the generator. This is in an app and not a gem.

So in the case below - How would I get 'Foo' to print on the generator code?

rails g block Foo

class BlockGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  puts #Foo (file name)#
end

I've tried with both NamedBase and base generators and every method I can find.

Any help would be greatly appreciated!

# EDIT
$ rails g block Foo

class BlockGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)
  argument :generator_name, type: :string

  puts #Foo (file name)#
end

#result

block
No value provided for required arguments 'generator_name'


$ rails generate block :generator_name => testing

 #result

 is empty, nothing is printed to the console. 

原文:https://stackoverflow.com/questions/40941833
更新时间:2022-11-01 15:11

最满意答案

似乎对模型进行非规范化解决了这个问题。

对于老一代设备,永远不会再为父实体执行ManagedObjects。


Seems that denormalizing the model resolved this issues.

Will not ever do ManagedObjects with a parent entity again for older generation devices.

相关问答

更多
  • 使用代码苹果在这里提供 Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus status = [reachability currentReachabilityStatus]; if(status == NotReachable) { //No internet } else if (status == ...
  • 3G不是一项技术,而是一系列移动通信标准。 全球不同地区有不同的标准。 在美国,使用CDMA(不确定WCDMA是否也是如此),而在欧洲使用最近升级到HSPA的WCDMA(或更好地称为UMTS)。 这些都是3G家庭标准。 2G和2.5G系列标准的GPRS和EDGE是3G家族的前身。 从程序员的角度来看,所列标准GPRS,EDGE和3G(UMTS或CDMA)之间的唯一区别就是连接速度。 3G is not a single technology but a family of mobile communicat ...
  • 3G不支持(根据我的经验,在文档中找不到它).mov。 转换为其他格式可能是最佳选择。 您可以尝试使用quicktime转换为“iPhone(手机)”,因为该格式将更小。 The 3G doesn't support (in my experience, can't find it in the docs) .mov. Converting to another format is probably the best option. You might try using quicktime to conv ...
  • 如果您上传的新版本没有arm6支持,则3G用户将看不到更新,并将保留在最后支持的版本上。 但是,没有安装以前版本的3G用户将无法再安装它。 如果您保留旧版本的arm6支持并创建一个仅限arm7的新应用程序ID,则3GS,4和4S用户将不得不重新下载新版本。 App Store永远不允许安装旧版本。 If you upload a new version which does not have arm6 support, 3G users will not see the update and will re ...
  • 根据Apple的文档 ,WiFi是首先选择的。 如果失败,则转到下一个可用(并且可能是最快的)蜂窝网络数据连接。 这是程序员在为iOS设计应用程序时不必担心的事情。 According to Apple's documentation, WiFi is what is chosen first. If that fails, then it goes to the next available (and presumably fastest) cellular network data connection ...
  • 这是一段代码,可能有助于: // Matt Brown's get WiFi IP addy solution // Author gave permission to use in Cookbook under cookbook license // http://mattbsoftware.blogspot.com/2009/04/how-to-get-ip-address-of-iphone-os-v221.html + (NSString *) localAddressForInterface:(N ...
  • 多任务处理和本地通知是两回事。 运行iOS4的每台设备都支持本地通知。 为了了解设备是否支持多任务处理,您可以使用它 UIDevice* device = [UIDevice currentDevice]; backgroundSupported = NO; if ([device respondsToSelector:@selector(isMultitaskingSupported)]) backgroundSupported = [device isMultitaskingSupported]; M ...
  • 对于相同的iOS版本,音频框架似乎是相同的(2G除外)。 然而,物理麦克风(和声学环境)是不同的。 人们发布了各种测试结果,例如: http://blog.faberacoustical.com/2009/iphone/iphone-microphone-frequency-response-comparison/ 和 http://blog.faberacoustical.com/2010/iphone/iphone-4-audio-and-frequency-response-limitations/ ...
  • 似乎对模型进行非规范化解决了这个问题。 对于老一代设备,永远不会再为父实体执行ManagedObjects。 Seems that denormalizing the model resolved this issues. Will not ever do ManagedObjects with a parent entity again for older generation devices.
  • 检查的最佳方法是使用sysctlbyname("hw.machine", ...) 如何判断您的代码是在iPhone还是iPhone3G上运行? 3GS的返回结果应为“iPhone2,1” The best way to check is to use sysctlbyname("hw.machine", ...) as per How to tell if your code is running on an iPhone or an iPhone3G? The returned result for 3 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)