2012-08-12 17 views
34

मैं "हेड फर्स्ट रेल" पुस्तक से निर्देशों का पालन करने की कोशिश कर रहा हूं और पेज 50 पर यह एक मॉडल बनाने के लिए कहता है लेकिन मैं रेल कमांड का उपयोग कर मॉडल बनाने में असमर्थ हूं।रेल मॉडल उत्पन्न करते हैं

जब मैं इस प्रॉम्प्ट पर इस टाइप करें: स्थानीय होस्ट: ~ घर $

rails generate model ad name:string description:text price:decimal seller_id:integer email:string img_url:string 

मैं इस मिल:

रेल
Usage: 
    rails new APP_PATH [options] 

Options: 
    -r, [--ruby=PATH]    # Path to the Ruby binary of your choice 
           # Default: /Users/home/.rvm/rubies/ruby-1.9.3-p125/bin/ruby 
    -b, [--builder=BUILDER]  # Path to a application builder (can be a filesystem path or URL) 
    -m, [--template=TEMPLATE]  # Path to an application template (can be a filesystem path or URL) 
     [--skip-gemfile]   # Don't create a Gemfile 
     [--skip-bundle]   # Don't run bundle install 
    -G, [--skip-git]    # Skip Git ignores and keeps 
    -O, [--skip-active-record]  # Skip Active Record files 
    -S, [--skip-sprockets]   # Skip Sprockets files 
    -d, [--database=DATABASE]  # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) 
           # Default: sqlite3 
    -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library 
           # Default: jquery 
    -J, [--skip-javascript]  # Skip JavaScript files 
     [--dev]     # Setup the application with Gemfile pointing to your Rails checkout 
     [--edge]     # Setup the application with Gemfile pointing to Rails repository 
    -T, [--skip-test-unit]   # Skip Test::Unit files 
     [--old-style-hash]   # Force using old style hash (:foo => 'bar') on Ruby >= 1.9 

Runtime options: 
    -f, [--force] # Overwrite files that already exist 
    -p, [--pretend] # Run but do not make any changes 
    -q, [--quiet] # Suppress status output 
    -s, [--skip]  # Skip files that already exist 

Rails options: 
    -h, [--help]  # Show this help message and quit 
    -v, [--version] # Show Rails version number and quit 

Description: 
    The 'rails new' command creates a new Rails application with a default 
    directory structure and configuration at the path you specify. 

    You can specify extra command-line arguments to be used every time 
    'rails new' runs in the .railsrc configuration file in your home directory. 

    Note that the arguments specified in the .railsrc file don't affect the 
    defaults values shown above in this help message. 

Example: 
    rails new ~/Code/Ruby/weblog 

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog. 
    See the README in the newly created application to get going. 
localhost:~ home$ 

मैं उपयोग कर रहा हूँ -v 3.2.8 और रूबी 1.9.3p125

+0

आप अपने रेल परियोजना dir में सीडी किया था? – PeterWong

+0

मुझे लगता है कि यह समस्या हो सकती है। मेरे पास कोई परियोजना नहीं है। पुस्तक रेल संस्करण 2.1 के लिए लिखी गई है। इस ट्यूटोरियल में मैं 'रेल मेबे' का उपयोग करके एक निर्देशिका बनाना था, लेकिन वह आदेश रेल 3.2.8 में काम नहीं करता है। मुझे 'रेल नई मेबे' का उपयोग नहीं करना चाहिए क्योंकि मुझे मैन्युअल रूप से मॉडल और नियंत्रक बनाना है। मुझे लगता है कि पुस्तक में एक कदम गायब है। – Livi17

उत्तर

63

कोड ठीक है लेकिन आप गलत निर्देशिका में हैं। आपको इन आदेशों को अपने रेल प्रोजेक्ट-निर्देशिका के अंदर चलाना होगा।

खरोंच से वहाँ पहुँचने के लिए सामान्य तरीका है:

$ rails new PROJECT_NAME 
$ cd PROJECT_NAME 
$ rails generate model ad \ 
    name:string \ 
    description:text \ 
    price:decimal \ 
    seller_id:integer \ 
    email:string img_url:string 
+1

यह सबक आपको यह दिखाने के लिए किया गया था कि मैन्युअल रूप से मॉडल और नियंत्रक कैसे बनाएं। यह कहता है कि "रेल नई मेबे" का उपयोग करके एक मचान ऐप बनाता है, लेकिन एक मचान वाला ऐप हमें ज़्यादा ज़रूरत से अधिक प्रदान करता है। इसलिए हमें "रेल मॉडल मॉडल ब्लाह: स्ट्रिंग" उत्पन्न करने वाले मॉडल का मैन्युअल रूप से मैन्युअल रूप से बनाना होगा। सिवाय इसके कि यह हमें नहीं बताता कि पहले ऐप निर्देशिका कैसे बनाएं। मुझे लगता है कि पुस्तक में एक कदम गायब है। – Livi17

+0

मैं – Livi17

+0

से ऊपर अपने सुझाव का प्रयास करूंगा 'रेल नई मेबे' कमांड एक मचान ऐप उत्पन्न नहीं करता है। यह केवल रेल-ऐप के स्केलेटन का उत्पादन करता है। इसके बिना, आप अपना आवेदन लिखना शुरू नहीं कर सकते हैं। –

2

आप पहली बार नई रेल आवेदन बनाना होगा। भागो

rails new mebay 
cd mebay 
bundle install 
rails generate model ... 

और रेल को खोजने के लिए 3 ट्यूटोरियल की कोशिश, वहाँ 2.1 गाइड (http://guides.rubyonrails.org/getting_started.html) के बाद से परिवर्तन का एक बहुत अच्छी शुरुआत बिंदु रहे हैं।

1

मेरे लिए क्या हुआ कि मैं रेल नई रेल नया chapter_2 लेकिन RVM --default रेल था 4.0.2 मणि ​​के साथ एप्लिकेशन को उत्पन्न था, लेकिन मेरी chapter_2 परियोजना रेल 3.2.16 के साथ एक नया gemset का उपयोग करें।

तो जब मैं

rails generate scaffold User name:string email:string 

कंसोल से पता चला है

Usage: 
    rails new APP_PATH [options] 

तो मैं RVM और रेल 3.2.16 मणि के साथ gemset तय है, और फिर उसके बाद एप्लिकेशन फिर उत्पन्न मैं भाग गया

rails generate scaffold User name:string email:string 

मार डाला और यह

०१२३५१६४१० काम किया
7

त्रुटि से पता चलता है कि आपने या तो रेल परियोजना अभी तक नहीं बनाई है या आप रेल परियोजना निर्देशिका में नहीं हैं।

मान लीजिए कि आप Myapp प्रोजेक्ट पर काम कर रहे हैं या नहीं। आपको अपनी कमांड लाइन पर उस प्रोजेक्ट निर्देशिका में जाना होगा और फिर मॉडल जेनरेट करना होगा। यहां कुछ चरण दिए गए हैं जिन्हें आप संदर्भित कर सकते हैं।

उदाहरण: अभी तक रेल एप्लिकेशन का निर्माण नहीं किया आप यह सोचते हैं:

$> rails new myapp 
$> cd myapp 

अब आप अपने कमांडलाइन से मॉडल उत्पन्न करते हैं।

$> rails generate model your_model_name 
संबंधित मुद्दे