无法仅显示用户拥有的嵌套对象

时间:2014-11-27 16:10:22

标签: ruby-on-rails-4

我有一个拥有自己的立场的用户,我只需要显示他拥有的用户。

我的控制器是:

class StandupsController < ApplicationController

def index
    user = User.find(params[:user_id])

    @standups = user.standups
end

def new
    @standup = Standup.new

    3.times{
        @standup.yesterday_items.build
        @standup.today_items.build
    }
end

def create
    @standup = Standup.new(standup_params)

    if @standup.save
        redirect_to standups_path
    else
        render 'new'
    end
end

def edit
    @standup = Standup.find(params[:id])

    (3-@standup.yesterday_items.count).times{ @standup.yesterday_items.build }
    (3-@standup.today_items.count).times{ @standup.today_items.build }
end

def update
    @standup = Standup.find(params[:id])

    if @standup.update(standup_params)
        redirect_to standups_path
    else
        render 'edit'
    end
end

def destroy
    @standup = Standup.find(params[:id])
    @standup.destroy

    redirect_to standups_path
end

private
def standup_params
    params.require(:standup).permit(yesterday_items_attributes: [:id, 1, :item, :_destroy], today_items_attributes: [:id, 1, :item, :_destroy])
end

end

我的观点是:

<h1>Standups: </h1>

<% @standups.each do |standup| %>

<h2><%= standup.created_at.to_date %></h2>

<h3>Yesterday items:</h3>
<% standup.yesterday_items.each do |yesterday_item| %> 
    <p>- <%= yesterday_item.item %></p>
<% end %>

<h3>Today items:</h3>
<% standup.today_items.each do |today_item| %>
    <p>- <%= today_item.item %></p>
<% end %>



<% end %>

<br>


<%= button_to 'Home', welcome_index_path, :method => :get %>

与之相关的链接是:

<%= button_to 'My Standups', user_standups_path(current_user), :method => :get %>

网址看起来不错,但有一个? ad结束时和我用@standups = user.standups替换 @standups = Standup.all它工作正常,但这不是我需要的行为,有没有人知道问题可能是什么?

更新:

控制台日志:

←[36m2014-11-27T22:32:56.638102+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:170:in `select'
←[36m2014-11-27T22:32:56.638145+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_comman
d!'
←[36m2014-11-27T22:32:56.723015+00:00 app[web.1]:←[0m => Notice: server is liste
ning on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
←[36m2014-11-27T22:32:56.638142+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap'
←[36m2014-11-27T22:32:56.723016+00:00 app[web.1]:←[0m => Ctrl-C to shutdown serv
er
←[33m2014-11-27T22:31:46.458057+00:00 heroku[router]:←[0m at=info method=POST pa
th="/accounts/sign_in" host=sheltered-reef-3662.herokuapp.com request_id=311d154
f-cd22-4396-82e9-475e7a598601 fwd="188.2.48.160" dyno=web.1 connect=1ms service=
143ms status=302 bytes=1054
←[36m2014-11-27T22:32:56.638096+00:00 app[web.1]:←[0m [2014-11-27 22:32:56] FATA
L SignalException: SIGTERM
←[36m2014-11-27T22:32:56.638144+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server'
←[36m2014-11-27T22:32:56.723011+00:00 app[web.1]:←[0m => Rails 4.1.8 application
starting in production on http://0.0.0.0:53991
←[36m2014-11-27T22:32:56.638139+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/server.rb:69:in `start'
←[36m2014-11-27T22:32:56.723006+00:00 app[web.1]:←[0m => Booting WEBrick
←[36m2014-11-27T22:32:56.638141+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in s
erver'
←[36m2014-11-27T22:32:56.723013+00:00 app[web.1]:←[0m => Run `rails server -h` f
or more startup options
←[36m2014-11-27T22:32:52.491573+00:00 heroku[web.1]:←[0m State changed from up t
o starting
←[36m2014-11-27T22:32:57.715849+00:00 heroku[web.1]:←[0m Process exited with sta
tus 143
←[33m2014-11-27T22:33:49.538242+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-403c76ae95aebf08f50e1ae6511bc92a.css" host=sheltered-reef
-3662.herokuapp.com request_id=2c27a927-411c-4f19-9ffa-c01473a21fdd fwd="188.2.4 
8.160" dyno=web.1 connect=0ms service=9ms status=404 bytes=1829
←[33m2014-11-27T22:33:49.539547+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-2a94f64206840412f683051ee4ad5d09.js" host=sheltered-reef-
3662.herokuapp.com request_id=a53821a9-49d9-467c-ae20-60b44017fb33 fwd="188.2.48    
.160" dyno=web.1 connect=0ms service=7ms status=404 bytes=1829
←[33m2014-11-27T22:33:49.381350+00:00 heroku[router]:←[0m at=info method=GET pat
h="/" host=sheltered-reef-3662.herokuapp.com request_id=fa193bbd-d288-44ee-b353-
5776866d30ef fwd="188.2.48.160" dyno=web.1 connect=1ms service=193ms status=200
bytes=2043
←[33m2014-11-27T22:33:50.872275+00:00 heroku[router]:←[0m at=info method=POST pa
th="/users/2/standups" host=sheltered-reef-3662.herokuapp.com request_id=02f6a14
3-0651-47fe-b04e-74f18702fbcb fwd="188.2.48.160" dyno=web.1 connect=4ms service=
28ms status=400 bytes=264
←[36m2014-11-27T22:32:58.495380+00:00 app[web.1]:←[0m [2014-11-27 22:32:58] INFO
WEBrick 1.3.1
←[36m2014-11-27T22:32:58.495403+00:00 app[web.1]:←[0m [2014-11-27 22:32:58] INFO
ruby 2.0.0 (2014-11-13) [x86_64-linux]
2
←[36m014-11-27T22:32:58.495850+00:00 app[web.1]:←[0m [2014-11-27 22:32:58] INFO
WEBrick::HTTPServer#start: pid=2 port=18070
←[36m2014-11-27T22:32:59.038459+00:00 heroku[web.1]:←[0m State changed from star
ting to up
←[32m2014-11-27T22:35:06+00:00 heroku[slug-compiler]:←[0m Slug compilation start
ed
←[35m2014-11-27T22:35:30.587421+00:00 heroku[api]:←[0m Deploy 352a7f7 by nemanja
.keca@gmail.com
←[35m2014-11-27T22:35:30.587421+00:00 heroku[api]:←[0m Release v219 created by n
emanja.keca@gmail.com
←[36m2014-11-27T22:35:31.232997+00:00 heroku[web.1]:←[0m State changed from up t
o starting
←[36m2014-11-27T22:35:33.253147+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:170:in `select'
←[36m2014-11-27T22:35:33.253137+00:00 app[web.1]:←[0m [2014-11-27 22:35:33] FATA
L SignalException: SIGTERM
←[36m2014-11-27T22:35:33.280515+00:00 app[web.1]:←[0m Exiting
←[36m2014-11-27T22:35:33.280511+00:00 app[web.1]:←[0m => Notice: server is liste
ning on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
←[36m2014-11-27T22:35:33.253155+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
←[36m2014-11-27T22:35:33.253157+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
←[36m2014-11-27T22:35:33.253163+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap'
←[36m2014-11-27T22:35:33.253164+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server'
←[36m2014-11-27T22:35:33.253166+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_comman
d!'
←[36m2014-11-27T22:35:33.253168+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
←[36m2014-11-27T22:35:33.253170+00:00 app[web.1]:←[0m   bin/rails:4:in `require'

←[36m2014-11-27T22:35:33.253171+00:00 app[web.1]:←[0m   bin/rails:4:in `<main>'
←[36m2014-11-27T22:35:33.253178+00:00 app[web.1]:←[0m [2014-11-27 22:35:33] INFO
going to shutdown ...
←[36m2014-11-27T22:35:33.253180+00:00 app[web.1]:←[0m [2014-11-27 22:35:33] INFO
WEBrick::HTTPServer#start done.
←[36m2014-11-27T22:35:33.280499+00:00 app[web.1]:←[0m => Booting WEBrick
←[36m2014-11-27T22:35:33.280507+00:00 app[web.1]:←[0m => Rails 4.1.8 application
starting in production on http://0.0.0.0:18070
←[36m2014-11-27T22:35:33.280509+00:00 app[web.1]:←[0m => Run `rails server -h` f
or more startup options
←[36m2014-11-27T22:35:33.253158+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/server.rb:69:in `start'
←[36m2014-11-27T22:35:33.253160+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in s
erver'
←[36m2014-11-27T22:35:33.253149+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
←[36m2014-11-27T22:35:33.280513+00:00 app[web.1]:←[0m => Ctrl-C
to shutdown server
←[36m2014-11-27T22:35:33.253151+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:32:in `start'
←[36m2014-11-27T22:35:33.253153+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:160:in `start'
←[36m2014-11-27T22:35:32.900228+00:00 heroku[web.1]:←[0m Stopping all processes
with SIGTERM
←[36m2014-11-27T22:35:34.105306+00:00 heroku[web.1]:←[0m Starting process with c
ommand `bin/rails server -p 43125 -e production`
←[36m2014-11-27T22:35:33.946777+00:00 heroku[web.1]:←[0m Process exited with sta
tus 143
←[32m2014-11-27T22:35:35+00:00 heroku[slug-compiler]:←[0m Slug compilation finis
hed
←[36m2014-11-27T22:35:37.033363+00:00 app[web.1]:←[0m [2014-11-27 22:35:37] INFO
WEBrick::HTTPServer#start: pid=2 port=43125
←[36m2014-11-27T22:35:37.167020+00:00 heroku[web.1]:←[0m State changed from star
ting to up
←[36m2014-11-27T22:35:37.033034+00:00 app[web.1]:←[0m [2014-11-27 22:35:37] INFO
WEBrick 1.3.1
←[36m2014-11-27T22:35:37.033055+00:00 app[web.1]:←[0m [2014-11-27 22:35:37] INFO
ruby 2.0.0 (2014-11-13) [x86_64-linux]
←[33m2014-11-27T22:36:02.461266+00:00 heroku[router]:←[0m at=info method=GET pat
h="/" host=sheltered-reef-3662.herokuapp.com request_id=a01b075e-68b3-4b0c-ad97-
41f776ae652d fwd="188.2.48.160" dyno=web.1 connect=1ms service=106ms status=304
bytes=846
←[33m2014-11-27T22:36:02.615572+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-403c76ae95aebf08f50e1ae6511bc92a.css" host=sheltered-reef
-3662.herokuapp.com request_id=2736423f-07ee-4ba
0-8395-b36e5ed8ca6e fwd="188.2.48.160" dyno=web.1 connect=2ms service=7ms status
=404 bytes=1829
←[33m2014-11-27T22:36:02.623786+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-2a94f64206840412f683051ee4ad5d09.js" host=sheltered-reef-
3662.herokuapp.com request_id=7a50f5ac-c506-4c0d-ad14-40bc9ef6ec05 fwd="188.2.48
.160" dyno=web.1 connect=2ms service=6ms status=404 bytes=1829
←[33m2014-11-27T22:36:05.239861+00:00 heroku[router]:←[0m at=info method=POST pa
th="/users/2/standups" host=sheltered-reef-3662.herokuapp.com request_id=7b8a801
b-3893-4c90-84bd-decc61221afe fwd="188.2.48.160" dyno=web.1 connect=2ms service=
70ms status=400 bytes=264
←[32m2014-11-27T22:36:46+00:00 heroku[slug-compiler]:←[0m Slug compilation start
ed
←[32m2014-11-27T22:37:19+00:00 heroku[slug-compiler]:←[0m Slug compilation finis
hed
←[35m2014-11-27T22:37:19.511526+00:00 heroku[api]:←[0m Deploy 003c6cf by nemanja
.keca@gmail.com
←[35m2014-11-27T22:37:19.511967+00:00 heroku[api]:←[0m Release v220 created by n
emanja.keca@gmail.com
←[36m2014-11-27T22:37:19.676753+00:00 heroku[web.1]:←[0m State changed from up t
o starting    
←[36m2014-11-27T22:37:21.708354+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:170:in `select'
←[36m2014-11-27T22:37:21.708358+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l 
ib/ruby/2.0.0/webrick/server.rb:32:in `start'
←[36m2014-11-27T22:37:21.708356+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2014-11-27T22:37:21.708347+00:
←[36m00 app[web.1]:←[0m [2014-11-27 22:37:21] FATAL SignalException: SIGTERM 
←[36m2014-11-27T22:37:21.708360+00:00 app[web.1]:←[0m   /app/vendor/ruby-2.0.0/l
ib/ruby/2.0.0/webrick/server.rb:160:in `start'
←[36m2014-11-27T22:37:21.708361+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
←[36m2014-11-27T22:37:21.708363+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
←[36m2014-11-27T22:37:21.708369+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server'
←[36m2014-11-27T22:37:21.708364+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/server.rb:69:in `start'
←[36m2014-11-27T22:37:21.708366+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in s
erver'
←[36m2014-11-27T22:37:21.708368+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap'
←[36m2014-11-27T22:37:21.708371+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_comman
d!'
←[36m2014-11-27T22:37:21.708373+00:00 app[web.1]:←[0m   /app/vendor/bundle/ruby/
2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
←[36m2014-11-27T22:37:21.708376+00:00 app[web.1]:←[0m   bin/rails:4:in `<main>'
←[36m2014-11-27T22:37:21.708383+00:00 app[web.1]:←[0m [2014-11-27 22:37:21] INFO
going to shutdown ...
←[36m2014-11-27T22:37:21.708384+00:00 app[web.1]:←[0m [2014-11-27 22:37:21] INFO
WEBrick::HTTPServer#start done.
←[36m2014-11-27T22:37:21.736498+00:00 app[web.1]:←[0m => Booting WEBrick
←[36m2014-11-27T22:37:21.736506+00:00 app[web.1]:←[0m => Rails 4.1.8 application
starting in production on http://0.0.0.0:43125
←[36m2014-11-27T22:37:21.736508+00:00 app[web.1]:←[0m => Run `rails server -h` f
or more startup options
←[36m2014-11-27T22:37:21.736511+00:00 app[web.1]:←[0m => Ctrl-C to shutdown serv
er
←[36m2014-11-27T22:37:21.736510+00:00 app[web.1]:←[0m => Notice: server is liste
ning on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
←[36m2014-11-27T22:37:21.708374+00:00 app[web.1]:←[0m   bin/rails:4:in `require'

←[36m2014-11-27T22:37:21.736513+00:00 app[web.1]:←[0m Exiting
←[36m2014-11-27T22:37:21.367689+00:00 heroku[web.1]:←[0m Stopping all processes
with SIGTERM
←[36m2014-11-27T22:37:22.423347+00:00 heroku[web.1]:←[0m Process exited with sta
tus 143
←[36m2014-11-27T22:37:22.908752+00:00 heroku[web.1]:←[0m Starting process with c
ommand `bin/rails server -p 59165 -e production`
←[36m2014-11-27T22:37:26.195853+00:00 app[web.1]:←[0m [2014-11-27 22:37:26] INFO
ruby 2.0.0 (2014-11-13) [x86_64-linux]
←[36m2014-11-27T22:37:26.195834+00:00 app[web.1]:←[0m [2014-11-27 22:37:26] INFO
WEBrick 1.3.1
←[36m2014-11-27T22:37:26.196258+00:00 app[web.1]:←[0m [2014-11-27 22:37:26] INFO
WEBrick::HTTPServer#start: pid=2 port=59165
←[36m2014-11-27T22:37:26.739341+00:00 heroku[web.1]:←[0m State changed from star
ting to up
←[33m2014-11-27T22:51:07.209438+00:00 heroku[router]:←[0m at=info method=GET pat
h="/" host=sheltered-reef-3662.herokuapp.com request_id=1532eef2-f0e6-4b36-8fec-
7ad9785a9461 fwd="188.2.48.160" dyno=web.1 connect=1ms service=156ms status=200
bytes=1940
←[33m2014-11-27T22:51:07.364756+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-2a94f64206840412f683051ee4ad5d09.js" host=sheltered-reef-
3662.herokuapp.com request_id=9ff3aaf8-f7f9-43f0-a64a-9856689b4f91 fwd="188.2.48
.160" dyno=web.1 connect=1ms service=9ms status=404 bytes=1829
←[33m2014-11-27T22:51:07.359284+00:00 heroku[router]:←[0m at=info method=GET pat
h="/assets/application-403c76ae95aebf08f50e1ae6511bc92a.css" host=sheltered-reef
-3662.herokuapp.com request_id=b93ebaa5-103c-41b0-954b-cccb019eb347 fwd="188.2.4
8.160" dyno=web.1 connect=1ms service=8ms status=404 bytes=1829
←[33m2014-11-27T22:51:09.228449+00:00 heroku[router]:←[0m at=info method=GET pat
h="/users/2/standups" host=sheltered-reef-3662.herokuapp.com request_id=b6f7823f
-077e-449d-8c3f-b8ef77acea3e fwd="188.2.48.160" dyno=web.1 connect=1ms service=8
8ms status=500 bytes=1754}

更新:

rake routes:

                Prefix Verb   URI Pattern
  Controller#Action
      new_user_session GET    /accounts/sign_in(.:format)
  devise/sessions#new
          user_session POST   /accounts/sign_in(.:format)
  devise/sessions#create
  destroy_user_session DELETE /accounts/sign_out(.:format)
  devise/sessions#destroy
         user_password POST   /accounts/password(.:format)
  devise/passwords#create
     new_user_password GET    /accounts/password/new(.:format)
  devise/passwords#new
    edit_user_password GET    /accounts/password/edit(.:format)
  devise/passwords#edit
                       PATCH  /accounts/password(.:format)
  devise/passwords#update
                       PUT    /accounts/password(.:format)
  devise/passwords#update
cancel_user_registration GET    /accounts/cancel(.:format)
  devise/registrations#cancel
     user_registration POST   /accounts(.:format)
  devise/registrations#create
 new_user_registration GET    /accounts/sign_up(.:format)
  devise/registrations#new
edit_user_registration GET    /accounts/edit(.:format)
  devise/registrations#edit
                       PATCH  /accounts(.:format)
  devise/registrations#update
                       PUT    /accounts(.:format)
  devise/registrations#update
                       DELETE /accounts(.:format)
  devise/registrations#destroy
         welcome_index GET    /welcome/index(.:format)
  welcome#index
                  root GET    /
  welcome#index
 standup_yesterday_items GET    /standups/:standup_id/yesterday_items(.:format
)     yesterday_items#index
                       POST   /standups/:standup_id/yesterday_items(.:format
)     yesterday_items#create
new_standup_yesterday_item GET    /standups/:standup_id/yesterday_items/new(.:fo
rmat) yesterday_items#new
   edit_yesterday_item GET    /yesterday_items/:id/edit(.:format)
  yesterday_items#edit
        yesterday_item GET    /yesterday_items/:id(.:format)
  yesterday_items#show
                       PATCH  /yesterday_items/:id(.:format)
  yesterday_items#update
                       PUT    /yesterday_items/:id(.:format)
  yesterday_items#update
                       DELETE /yesterday_items/:id(.:format)
  yesterday_items#destroy
   standup_today_items GET    /standups/:standup_id/today_items(.:format)
  today_items#index
                       POST   /standups/:standup_id/today_items(.:format)
  today_items#create
new_standup_today_item GET    /standups/:standup_id/today_items/new(.:format
)     today_items#new
       edit_today_item GET    /today_items/:id/edit(.:format)
  today_items#edit
            today_item GET    /today_items/:id(.:format)
  today_items#show
                       PATCH  /today_items/:id(.:format)
  today_items#update
                       PUT    /today_items/:id(.:format)
  today_items#update
                       DELETE /today_items/:id(.:format)
  today_items#destroy
         user_standups GET    /users/:user_id/standups(.:format)
  standups#index
                       POST   /users/:user_id/standups(.:format)
  standups#create
      new_user_standup GET    /users/:user_id/standups/new(.:format)
  standups#new
          edit_standup GET    /standups/:id/edit(.:format)
  standups#edit
               standup GET    /standups/:id(.:format)
  standups#show
                       PATCH  /standups/:id(.:format)
  standups#update
                       PUT    /standups/:id(.:format)
  standups#update
                       DELETE /standups/:id(.:format)
  standups#destroy
                 users GET    /users(.:format)
  users#index
                       POST   /users(.:format)
  users#create
              new_user GET    /users/new(.:format)
  users#new
             edit_user GET    /users/:id/edit(.:format)
  users#edit
                  user GET    /users/:id(.:format)
  users#show
                       PATCH  /users/:id(.:format)
  users#update
                       PUT    /users/:id(.:format)
  users#update
                       DELETE /users/:id(.:format)
  users#destroy

用户模型:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  has_many :standups, dependent: :destroy
  accepts_nested_attributes_for :standups, :reject_if => :all_blank, :allow_destroy => true
end

站立模式:

class Standup < ActiveRecord::Base
    has_many :yesterday_items, dependent: :destroy
    has_many :today_items, dependent: :destroy
    accepts_nested_attributes_for :today_items, :reject_if => :all_blank, :allow_destroy => true
    accepts_nested_attributes_for :yesterday_items, :reject_if => :all_blank, :allow_destroy => true

    belongs_to :user
end

用户迁移:

class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
  ## Database authenticatable
  t.string :email,              null: false, default: ""
  t.string :encrypted_password, null: false, default: ""
  t.string :username,           null: false, default: ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, default: 0, null: false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.inet     :current_sign_in_ip
  t.inet     :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :users, :email,                unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token,   unique: true
# add_index :users, :unlock_token,         unique: true
end
end

站立迁移:     class CreateStandups&lt; ActiveRecord的::迁移     改变     drop_table:站起来     create_table:standups do | t |

  t.datetime :created_at

  t.references :user, index: true

  t.timestamps
end
end
end

编辑: 问题已经解决了,我已经处理了一些本地问题,在rails服务器上进行测试,这段代码没有任何问题,但我仍然无法在heroku上运行,即使是使用新的heroku也是如此构建和部署。

0 个答案:

没有答案