0

请帮我。我想创建一个社交网站,就像在 RailsS​​pace 书中一样。不幸的是,这本书很旧,我使用 Rails 3.2.3,为 Authentifiaction 和 bootstrap 设计。我刚刚为配置文件创建了一个模型、控制器和视图,但是当我以登录用户身份进入 lhost:3000/spec/edit 页面时,什么都没有。我的编辑视图中的表单未加载。

<% form_for :spec do |form| %>


<div>
    <label for="gender">Gender:</label>
    <%= radio_button :spec, :gender, "Male" %> Male 
    <%= radio_button :spec, :gender, "Female" %> Female
</div>
<div class="form_row">
    <label for="birthdate">Birthdate:</label>
    <%= date_select :spec, :birthdate, :start_year => Spec::START_YEAR, 
                                        :end_year => Time.now.year,
                                        :include_blank => true,
                                        :order => [:month, :day, :year] %>
</div>
<%= text_field_for form, "occupation" %>
<%= text_field_for form, "country" %>
<%= text_field_for form, "city" %>
<%= text_field_for form, "state" %>
<%= text_field_for form, "zip_code", Spec::ZIP_CODE_LENGTH %>

<%= submit_tag "Update", :class => "submit" %>

spec_controller.rb

    class SpecController < ApplicationController
  def index
    redirect_to 'user#index'
  end

  def edit

    @title = "Edit Spec"
    @user = current_user
    @user.spec ||= Spec.new
    @spec = @user.spec
    if param_posted?(:spec)
      if @user.spec.update_attributes(params[:spec])
        flash[:notice] = "Changes saved."
        redirect_to :controller => "user", :action => "index"
      end
    end
  end

end

规范rb

class Spec < ActiveRecord::Base
  attr_accessible :gender, :birthdate, :occupation, :city, :country, :zip_code

  #All_FIELDS = %w(gender birthdate occupation city country state zip_code)
  #STRING_FIELDS = %w(occupation city country state )
  #VALID_GENDERS = ["MALE", "FEMALE"]
  START_YEAR = 1990
  #VALID_DATES = DateTime.new(START_YEAR)..DateTime.now



ZIP_CODE_LENGTH = 5

  #validates STRING_FIELDS, :length => {maximum: 255}
  #validates :gender, :inclusion => { :in => VALID_GENDERS, :allow_nil => true,
  #  :message => "must be male or female" } 
  #validates :birthdate, :inclusion => { :in => VALID_DATES, :allow_nil => true,
  #  :message => "is invalid" }
  #validates :zip_code, :format => { :with => /(^$|^[0-9]{#{ZIP_CODE_LENGTH}}$)/,
  #  :message => "must be five digit numbers" }

  belongs_to :user
end

控制台显示:

Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-06-16 22:18:40
 +0200
Served asset /application.js - 304 Not Modified (0ms)
[2013-06-16 22:18:40] WARN  Could not determine content-length of response body.
 Set content-length of the response or set Response#chunked = true


Started GET "/assets/css/bootstrap.css" for 127.0.0.1 at 2013-06-16 22:18:40 +02
00
Served asset /css/bootstrap.css - 404 Not Found (3ms)

ActionController::RoutingError (No route matches [GET] "/assets/css/bootstrap.cs
s"):
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `
call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `c
all'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in
`call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `servi
ce'
  C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in
start_thread'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1
3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within resc
ues/layout (1.0ms)

请帮我。

宝石清单

*** LOCAL GEMS ***

actionmailer (3.2.13, 3.2.2, 2.3.10)
actionpack (3.2.13, 3.2.2, 2.3.10)
activemodel (3.2.13, 3.2.2)
activerecord (3.2.13, 3.2.2, 2.3.10)
activerecord-sqlserver-adapter (3.2.10)
activeresource (3.2.13, 3.2.2, 2.3.10)
activesupport (3.2.13, 3.2.2, 2.3.10)
acts-as-taggable-on (2.0.6)
addressable (2.3.4)
annotate (2.5.0, 2.4.1.beta1)
arel (3.0.2)
bcrypt-ruby (3.0.1 x86-mingw32, 3.0.0 x86-mingw32)
better_errors (0.9.0)
bigdecimal (1.1.0)
binding_of_caller (0.7.1)
bootstrap-sass (2.3.1.0, 2.1.0.0, 2.0.0)
bootstrap-will_paginate (0.0.9, 0.0.6, 0.0.5)
builder (3.0.4, 3.0.0)
bundler (1.3.4)
capybara (2.1.0, 1.1.2)
childprocess (0.3.9, 0.3.1)
coderay (1.0.9)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.2, 1.6.1, 1.2.0)
cucumber (1.3.2, 1.1.9)
cucumber-rails (1.3.1, 1.2.1)
database_cleaner (1.0.1, 0.7.0)
debug_inspector (0.0.2)
devise (2.2.4)
diff-lcs (1.2.4, 1.1.3)
email_spec (1.4.0)
erubis (2.7.0)
execjs (1.4.0, 1.3.0)
factory_girl (4.2.0, 4.1.0, 2.3.2)
factory_girl_rails (4.2.1, 4.1.0, 1.4.0)
faker (1.1.2, 1.0.1)
ffi (1.8.1 x86-mingw32, 1.0.11)
figaro (0.6.4)
gherkin (2.12.0 x86-mingw32, 2.9.0 x86-mingw32)
hike (1.2.3, 1.2.2, 1.2.1)
i18n (0.6.1, 0.6.0, 0.4.1)
io-console (0.3)
journey (1.0.4, 1.0.3)
jquery-rails (3.0.1, 3.0.0, 2.2.1, 2.0.2)
json (1.8.0, 1.7.7, 1.6.5, 1.5.5)
launchy (2.3.0)
mail (2.5.4, 2.5.3, 2.4.4)
mime-types (1.23, 1.22, 1.21, 1.17.2)
minitest (2.5.1)
multi_json (1.7.6, 1.7.5, 1.7.3, 1.7.2, 1.7.1, 1.1.0)
mysql (2.9.1 x86-mingw32)
mysql2 (0.3.11 x86-mingw32)
nokogiri (1.5.9 x86-mingw32, 1.5.2 x86-mingw32)
orm_adapter (0.4.0)
pg (0.14.1 x86-mingw32, 0.12.2 x86-mingw32)
polyglot (0.3.3)
quiet_assets (1.0.2)
rack (1.4.5, 1.4.1, 1.1.0)
rack-cache (1.2)
rack-ssl (1.3.3, 1.3.2)
rack-test (0.6.2, 0.6.1)
rails (3.2.13, 3.2.2, 2.3.10)
railties (3.2.13, 3.2.2)
rake (10.0.4, 10.0.3, 0.9.2.2, 0.8.7)
rb-readline (0.4.2)
rdoc (3.12.2, 3.12, 3.9.5)
RedCloth (4.2.9 x86-mingw32, 4.2.3)
rspec (2.11.0, 2.8.0, 1.3.0)
rspec-core (2.13.1, 2.11.1, 2.8.0)
rspec-expectations (2.13.0, 2.11.3, 2.8.0)
rspec-mocks (2.13.1, 2.11.3, 2.8.0)
rspec-rails (2.13.2, 2.11.0, 2.8.1, 1.3.2)
rubyzip (0.9.9, 0.9.6.1)
sass (3.2.9, 3.2.8, 3.2.7, 3.1.15)
sass-rails (3.2.6, 3.2.5, 3.2.4)
selenium-webdriver (2.32.1, 2.20.0)
shoulda (2.11.3)
sprockets (2.2.2, 2.1.2)
sqlite3 (1.3.7 x86-mingw32, 1.3.5 x86-mingw32)
sqlite3-ruby (1.3.3)
term-ansicolor (1.0.7)
thor (0.18.1, 0.17.0, 0.14.6)
tilt (1.4.1, 1.3.7, 1.3.6, 1.3.3)
tiny_tds (0.5.1 x86-mingw32)
treetop (1.4.14, 1.4.12, 1.4.10)
tzinfo (0.3.37, 0.3.32)
uglifier (2.1.1, 2.1.0, 2.0.1, 1.2.3)
warden (1.2.1)
websocket (1.0.7)
will_paginate (3.0.4, 3.0.3, 2.3.15)
xpath (2.0.0, 0.1.4)
4

1 回答 1

0

将此添加到您的Gemfile

gem 'less-rails'
gem 'twitter-bootstrap-rails'

然后运行bundle install,然后rails g boostrap:install。这应该做。

于 2013-06-17T11:38:28.250 回答