- 浏览: 70334 次
- 性别:
- 来自: 北京
最近访客 更多访客>>
最新评论
-
kldwq2002:
随便搜到这来的。看出您的代码有啥问题么?Exception被c ...
如何在Android当中显示网络图片 -
lamborghini_lp:
最近在看Ruby元编程,感觉不容易啊。
ruby元编程(入门收藏) -
boobmoom:
好东西 以后还得来看
ruby元编程(入门收藏) -
carlosbdw:
赞一个!欢迎来j-kanban.com看看!
转一篇好文章:用Rails实现“乐道”构想 -
akane:
纯净口水?
和NibiruTech团队交流后总结(最主要是和Kevin的交流)
Installing and Configuring Ruby Support
Contributed by <script language="JavaScript" type="text/javascript">
<!---->
</script>Chris Kutler <noscript></noscript>
September 2007 [Revision number: V6.0-1]
This document provides information about downloading, installing, and configuring Ruby support in the NetBeans IDE.
Downloading Ruby Support
If you do not have the NetBeans 6.0 IDE, go to the NetBeans IDE 6.0 Download Page, and download a version of the IDE that contains Ruby support. If you have a NetBeans IDE 6.0 installation that does not include Ruby support, complete the following steps to add Ruby support to the IDE.
- If your network uses a proxy, choose Tools > Options from the main menu, select Manual Proxy Settings, enter the HTTP Proxy and Port for your proxy, and click OK.
- Choose Tools > Plugins from the main menu.
- In the Plugins dialog box, click the Available Plugins tab, and scroll to the Ruby category, as shown below.
Figure 1: Plugin Manager
- Select the Ruby and Rails checkbox to get Ruby support for the NetBeans IDE.
- (Optional) Select the JRuby and Rails Distribution checkbox to download and install the JRuby software and the Ruby on Rails framework.
- (Optional) Select the Ruby Experimental Hints checkbox to include additional source code hints.
- Click Install.
The NetBeans IDE Installer appears. - In the NetBeans IDE Installer, click Next.
- Read the license agreement, then select the I Accept the Terms in All License Agreements radio button, and click Next.
- Click Install.
- After the installation completes, select either Restart IDE Now or Restart IDE Later and click Finish.
Configuring the IDE to Use Your Own Ruby Installation (Optional)
The first time that you create or open a Ruby project in the IDE, the IDE checks to see if you have any other Ruby installations in addition to the bundled JRuby software. If you do, the IDE displays a dialog box asking you to select which software to use.
If you decide to install the Ruby software later, you can complete the following steps to configure the IDE to configure the IDE to use your Ruby installation.
- In the IDE, choose Tools > Options from the main menu.
- Click Ruby, and, if necessary, click the Platform tab.
If you have not yet opened or created a Ruby project, the first time that you access the Platform tab, the IDE displays a Choose Ruby Interpreter dialog box that shows a list of available Ruby installations, as show below. If the dialog box does not appear, skip to Step 5.Figure 2: Choose Ruby Interpreter Dialog Box
- Select the Ruby interpreter that you want to use. If you do not see your Ruby interpreter on the list, click Other.
- Click Close.
- If you chose Other in the previous step, or if the Choose Ruby Interpreter dialog box did not appear, click the Browse button, navigate to the location of your Ruby binary, and click Open.
- Click OK to close the Options dialog box.
For information about obtaining Ruby software, see www.ruby-lang.org, instantrails.rubyforge.org, and locomotive.raaum.org.
Managing Gems
Gems are third-party Ruby libraries. The IDE provides a Ruby Gems manager for adding and maintaining gems.
To open the manager choose Tools > Ruby Gems from the main menu. Click the Installed tab to view a list of the gems that that have been installed for the registered Ruby platform (See the previous section for information about switching the IDE Ruby Platform setting to use your own Ruby installation). If you are using the JRuby platform and the IDE includes the JRuby and Rails Distribution plugin, the list contains the ActiveRecord-JDBC gem and the Rails framework, as shown below. Click the New Gems tab to see what gems are available to add to your Ruby platform.
Figure 3: Installed Tab in Ruby Gems Manager
Note. The RubyGems wiki page provides information on how enable the Ruby Gems manager to manage a native Ruby gems repository.
For more information about Ruby Gems, go to www.ruby-lang.org/en/libraries/. For more information about Rails, go to rubyonrails.org. Information about the ActiveRecord-JDBC gem can be found at jruby-extras.rubyforge.org/ActiveRecord-JDBC.
Using Database Servers With JRuby
You can access databases from a JRuby on Rails application in one of two ways.
- MySQL Adapter. The MySQL adapter is included with JRuby. You use this adapter just as you would with a native Ruby on Rails application.
- JDBC Adapter. As mentioned earlier, the JRuby and Rails Distribution plugin includes the ActiveRecord-JDBC gem, which enables your JRuby on Rails application to access database servers that provide JDBC 3.0 compliant drivers, such as MySQL, PostgresSQL, Oracle, HSQLDB, and Java DB (also known as Derby). The JDBC driver must be a pure Java driver. At the time of this writing, ActiveRecord-JDBC does not work with the Sqlite JDBC driver.
To use a JDBC connection, you must obtain a JDBC 3.0 client driver for your database server. For example, for MySQL, you can download the MySQL Connector/J driver. You must put a copy of the JDBC driver in theJRuby/lib
folder. Depending on your installation, this folder can be in one of two places.
- netbeans-install-dir
/ruby1/jruby-1.0.1/lib
- netbeans-user-dir
/jruby-1.0.1/JRuby/lib
To find the location of your JRuby installation, choose Tools > Options from the main menu, click Ruby, and click the Platform tab.
Note: The Java DB database server is bundled with the Glassfish application server, and its derbyclient.jar is in the glassfish-install-dir/javadb/lib folder.
To use the JDBC adapter in a Ruby on Rails project, select the Access Database Using JDBC checkbox when you create the project, as shown in the following figure.Figure 4: Selecting JDBC Database Access
Code Sample 1: JDBC Environment Setup if RUBY_PLATFORM =~ /java/ require 'rubygems' gem 'ActiveRecord-JDBC' require 'jdbc_adapter' end
When you use the JDBC adapter to access a database, you configure the database settings in the database.yml just as you would if you were using that database's Rails adapter, as shown below.
Code Sample 2: JDBC Database Configuration Example adapter: mysql database: my_development_database username: fred password: pfm host: localhost
When you create a Ruby on Rails project, the IDE adds the configurations to the database.yml for the database server that you select in step 2 of the Wizard as shown in Figure 4. If you are using a database server that is not in the drop-down list, you can edit the database configuration in the database.yml file after you create the project. - netbeans-install-dir
Important Note: If your operating system's host file does not contain localhost, use 127.0.0.1 instead. Note also that with some systems, the database setting must be in lower case letters.
Adding Databases
Several of the NetBeans tutorials require that you create a database for the data tables that are used by the tutorial. The steps for adding a database are different for each database server. Below are instructions for the MySQL and Java DB databases.
Adding MySQL Databases
- If it has not already been started, start the database server.
- (Optional) Use the following steps to create a user.
- At a command prompt, type the following command.
mysql -u
user-p
Omit the -p if the user does not have a password. Otherwise, when prompted, enter the password. The user must have global create user privileges or the insert privilege for the mysql database, such as the root user. - Use syntax similar to the following example to create a user.
CREATE USER 'fred'@'localhost'
identified by 'pfm'; - (Optional) Use syntax similar to the following to specify access privileges. In this example, the user is granted all privileges to all databases on the localhost database server.
GRANT ALL PRIVILEGES ON *.* TO 'fred'@'localhost';
- Type quit and press Enter to exit.
- At a command prompt, type the following command.
- To create a database, use syntax similar to the following at a command prompt.
mysqladmin -u fred -p create mydb_dev
Omit the -p if the user does not have a password. Otherwise, when prompted, enter the password. If you have not created users, you can useroot
as the username.
For more information about creating MySQL users and databases, see the MySQL Reference Manual.
Adding Java DB (Derby) Databases
If you installed a version of the IDE that includes the GlassFish application server, the IDE is configured to access the Java DB database that is provided with GlassFish. You can use the following steps to add a Java DB database from the IDE.
- From the main menu of the IDE, choose Tools > Java DB Database > Create Database.
- In the Create Java DB Database dialog box, enter the Database Name, User Name, and optional Password, as shown in the example below.
Figure 5: Create Java DB Database Dialog Box
- To specify a different location for the database, click Settings. In the Java DB Settings dialog box, click the Browse button for the Database Location, navigate to the folder in which you want the database to reside and click Open. Click OK to close the Java DB Settings dialog box.
- Click OK. The IDE creates the database and adds a node to the Databases section in the Services window, as shown below.
Figure 6: Database Node in Services Window
Registering Database Servers With the IDE
You do not need to register your database server with the IDE to use it from your Ruby project. However, by doing so you can create and view tables, and exercise SQL commands directly from the IDE. Some of the NetBeans Ruby tutorials require that you register the database with the IDE.
Note: If you installed a version of the IDE that includes the GlassFish server, the Java DB database is automatically registered with the IDE.
The following steps show how to register the MySQL database server with the IDE and how to establish a connection from the IDE to a database instance.
- If you haven't already, obtain a JDBC 3.0 compliant driver for your database server, such as the MySQL Connector/J driver.
- In the Services window, expand Databases, right-click the Drivers node and choose New Driver from the pop-up menu.
The New JDBC Driver dialog box appears. - Click Add, navigate to and select the driver's jar file, and click Open.
The New JDBC Driver dialog box displays the settings for the selected driver, as shown below.Figure 7: Selecting JDBC Database Access
- Click OK to close the New JDBC Driver dialog box.
The IDE adds a node for your database server under the Drivers node, as shown below. You can now establish connections with MySQL database instances.Figure 8: Registered Drivers
- To create a connection from the IDE to a database instance, such as the example mydb_development database described in the previous section, right-click the Databases node and choose New Connection.
The New Database Connection dialog box appears. - Select your driver from the Name drop-down list, such as MySQL (Connector/J driver).
- Using the pattern shown in the Database URL text box as a guide, type the database's URL into the text box. For example, jdbc:mysql://localhost:3306/mydb_development.
- Provide the User Name, and provide the Password if it is required, as shown below.
Figure 9: New Database Connection
- Click OK.
- When the connection is established, click OK to dismiss the dialog box.
The IDE adds a node for the connection under the Databases node. The badge for the node shows that the connection is open. When you next start the IDE, the badge will be broken to indicate that the connection is closed. To reconnect, right-click the node and choose connect, provide your password if it is required, and click OK.
Deploying a JRuby Application to GlassFish
By default, your JRuby applications run in the WEBrick browser. If you want to deploy a JRuby application to the GlassFish application server, you can package the application and its dependencies in a web archive (WAR) file, and make the WAR file available to the application server, as shown in the following steps.
- The deployed application will use the production database. Open the database.yml file to ensure that the production configuration is set correctly.
- When you create your JRuby application, you are given the option to add rake targets to support application server deployment, as shown in the following figure. If you intend to deploy to GlassFish, you should select this checkbox.
Figure 10: Option to Provide WAR Rake Targets
- In the Projects window, right-click the project's node and choose Rails Plugins from the pop-up menu.
- In the Rails Plugins dialog box, click the New Plugins tab.
- Select the entry for Goldspike, and click Install.
- Click OK to start the installation.
- Close both the Installation and Rails Plugins dialog boxes.
- Right-click the project's node and choose Run Rake Task > Refresh List from the pop-up menu.
- To package your application in a WAR file, right-click the project's node and choose Run Rake Task > War > Standalone > Create.
The IDE creates the WAR file and puts the file in the project's top folder. - If you are using the JDBC adapter, put a copy of your database server's JDBC client driver in glassfish-install-dir/lib and start (or restart) the GlassFish server.
At the time of this writing, you must use the JDBC adapter unless you are connecting to a MySQL database. - Place a copy of the newly created WAR file into GlassFish's autodeploy folder. For example, copy projects-folder/MyRubyApp/MyRubyApp.war to glassfish-install-dir/domains/domain1/autodeploy.
- In a web browser, goto the URL for the application. For example, http://localhost:8080/MyRubyApp.
Next Steps
-
To learn how to use the IDE to quickly build a Ruby on Rails application, go to Creating a Ruby Weblog in 10 Minutes.
-
To obtain support and stay informed of the latest changes to the NetBeans Ruby development features, join the <noscript></noscript>and <noscript></noscript>mailing lists.
- To submit your own NetBeans Ruby tutorial, please visit the NetBeans Community Docs page.
评论
而且个头小,只有19M。
相关推荐
在本文中,我们将深入探讨如何在您的计算机上安装和配置Ruby 1.8.6、Rails 2.0.2、RadRails 0.7.2 IDE以及MySQL数据库。这是一个适用于初学者和有一定经验的开发者的技术指南,旨在帮助您创建一个稳定的开发环境,...
尽管Ruby on Rails提供了丰富的功能和高效的工作流,但初次安装配置可能会让新手感到困惑。通过上述步骤,您可以手动完成Ruby on Rails的环境搭建,从而开启Rails开发之旅。记住,良好的开发环境是项目成功的基石,...
而Eclipse,作为一款功能强大的开源集成开发环境(IDE),支持多种编程语言,自然也包括Ruby on Rails。为了让Eclipse更好地适应Rails开发,诞生了名为RadRails的插件,它是专门为Eclipse设计的Rails开发工具集。 *...
总之,搭建Ruby on Rails环境需要安装Ruby、Rails、数据库驱动以及一个合适的IDE。在这个案例中,我们选择了RadRails作为开发工具。一旦环境配置完成,你就可以开始创建Web应用,体验Ruby on Rails带来的高效开发...
【Ruby on Rails手順】是关于使用Ruby编程语言和Ruby on Rails框架进行Web开发的一系列步骤。Ruby是一种面向对象的、动态的编程语言,而Ruby on Rails(简称Rails)是基于Ruby构建的一个开源Web应用程序框架,它遵循...
这可能包括设置路径变量、安装数据库(如SQLite或PostgreSQL)以及设置文本编辑器或IDE(如Visual Studio Code、Atom或IntelliJ IDEA)的Ruby和Rails插件。 6. **学习资源**:为了更好地理解和使用Ruby和Rails,...
Ruby for Eclipse 是一款专为Eclipse集成开发环境(IDE)设计的插件,它使得开发者能够在Eclipse中方便地编写、调试和运行Ruby语言的代码。这个插件极大地提升了Eclipse对Ruby开发的支持,提供了诸如代码高亮、自动...
Ruby Eclipse 插件是专为在Eclipse集成开发环境中(IDE)进行Ruby和Ruby on Rails开发设计的一款扩展工具。这款插件将Eclipse强大的功能与Ruby语言的灵活性结合在一起,为开发者提供了一站式的开发体验。 首先,让...
7. **集成Rails框架**:对于Ruby on Rails开发者来说,Ruby Eclipse插件还提供了Rails项目的模板支持,自动创建模型、控制器和视图,以及路由配置的编辑和检查。 8. **资源浏览器**:可视化显示项目的文件结构,...
RadRails是一款基于Eclipse的Ruby on Rails集成开发环境(IDE),提供了丰富的功能支持Rails应用开发。 1. **下载与安装** - 访问官网[http://www.radrails.org/](http://www.radrails.org/)下载RadRails,通常只...
- **安装Rails**: 使用RubyGems安装Rails 3,命令为 `$ gem install rails`。 - **选择IDE**: Aptana Studio 3是一个不错的选择,下载地址为www.aptana.com。 - **环境搭建** - **数据库**: SQLite3是默认支持的...
Rails提供了一系列的命令行工具,如`rails generate`(用于生成模型、控制器、迁移等),`rails console`(提供了一个交互式的Ruby环境,方便测试和调试),`rails dbconsole`(直接进入数据库控制台)等,这些都是...
标签 "源码 工具" 暗示了可能涉及源代码管理和开发工具的使用,比如 Git 用于版本控制,或者是 IDE(集成开发环境)如 TextMate 或 NetBeans 用于 Ruby on Rails 开发。 在压缩包中的 "libmySQL.dll" 文件,这通常...
在Windows环境下,使用NetBeans进行Rails开发需要一系列的配置步骤,因为Rails是一个基于Ruby的Web框架,而NetBeans是一款强大的集成开发环境(IDE),支持多种编程语言,包括Ruby。以下是一些关键知识点: 1. **...
在Windows操作系统上配置Ruby运行环境是一项重要的步骤,尤其对于开发者来说,这将使得你能够运行Ruby程序和使用相关的开发工具。Ruby是一种动态、面向对象的脚本语言,它以其简洁的语法和强大的元编程能力而受到...