Im new to ruby and I am trying to consume an api and display the data that I get from it but I keep on getting this error : undefined method `[]' for nil:NilClass. It's probably a stupid error but again i am new and cant figure it out. Here's my controller:
class RecipeController < ApplicationController
def Recipe
end
def search
recipe = find_recipe(params[:targetCalories])
unless recipe
flash[:alert] = 'Recipe not found'
return render action: :Recipe
end
#recipe = recipe.first
end
private
def request_api(url)
response = Excon.get(
url,
headers: {
'X-RapidAPI-Host' => URI.parse(url).host,
'X-RapidAPI-Key' => ENV.fetch('RAPIDAPI_API_KEY')
}
)
return nil if response.status != 200
JSON.parse(response.body)
end
def find_recipe(name)
request_api(
"https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/mealplans/generate/#{URI.encode(targetCalories)}"
)
end
end
And here's my html:
<div class="container">
<div class="row">
<div class="col-lg-12 mt-5">
<% if flash[:alert] %>
<div class="alert alert-warning"><%= flash[:alert] %></div>
<% end %>
<div class="mx-auto mt-5" style="width: 400px">
<%= form_with(url: search_path, method: 'get', local: true) do %>
<div class="form-group">
<%= label_tag :country, 'Type amount of calories '%>
<%= text_field_tag :country, nil, placeholder: 'Eg. 1000', class: 'form-control' %>
</div>
<%= button_tag 'Search', class: 'btn btn-success btn-block' %>
<% end %>
</div>
</div>
</div>
<div class="container">
<div class="row mt-5">
<div class="col-lg-6">
<h4>Recipe info</h4>
<dl>
<dt>Day</dt>
<dd><%= #recipe['day'] %></dd>
<dt>Capital</dt>
<dd><%= #recipe['type'] %></dd>
<dt>Currency</dt>
<dd><%= #recipe['value'].join(', ') %></dd>
</dl>
</div>
</div>
</div>
Edit: this is the full stack trace
app/views/recipe/Recipe.html.erb:26
actionview (6.0.2.1) lib/action_view/base.rb:274:in `_run'
actionview (6.0.2.1) lib/action_view/template.rb:185:in `block in render'
activesupport (6.0.2.1) lib/active_support/notifications.rb:182:in `instrument'
actionview (6.0.2.1) lib/action_view/template.rb:386:in `instrument_render_template'
actionview (6.0.2.1) lib/action_view/template.rb:183:in `render'
actionview (6.0.2.1) lib/action_view/renderer/template_renderer.rb:59:in `block (2 levels) in render_template'
actionview (6.0.2.1) lib/action_view/renderer/abstract_renderer.rb:89:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionview (6.0.2.1) lib/action_view/renderer/abstract_renderer.rb:88:in `instrument'
actionview (6.0.2.1) lib/action_view/renderer/template_renderer.rb:58:in `block in render_template'
actionview (6.0.2.1) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
actionview (6.0.2.1) lib/action_view/renderer/template_renderer.rb:57:in `render_template'
actionview (6.0.2.1) lib/action_view/renderer/template_renderer.rb:13:in `render'
actionview (6.0.2.1) lib/action_view/renderer/renderer.rb:61:in `render_template_to_object'
actionview (6.0.2.1) lib/action_view/renderer/renderer.rb:29:in `render_to_object'
actionview (6.0.2.1) lib/action_view/rendering.rb:118:in `block in _render_template'
actionview (6.0.2.1) lib/action_view/base.rb:304:in `in_rendering_context'
actionview (6.0.2.1) lib/action_view/rendering.rb:117:in `_render_template'
actionpack (6.0.2.1) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (6.0.2.1) lib/action_view/rendering.rb:103:in `render_to_body'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (6.0.2.1) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (6.0.2.1) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (6.0.2.1) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
C:/Ruby26-x64/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (6.0.2.1) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:85:in `cleanup_view_runtime'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:34:in `cleanup_view_runtime'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:43:in `render'
remotipart (1.4.4) lib/remotipart/render_overrides.rb:23:in `render'
actionpack (6.0.2.1) lib/action_controller/metal/implicit_render.rb:35:in `default_render'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.2) lib/rack/etag.rb:27:in `call'
rack (2.2.2) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.2) lib/rack/head.rb:12:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
undefined method `[]' for nil:NilClass on
app/views/recipe/Recipe.html.erb:26
Your #recipe instance variable is nil. Make sure you assign a value to it in your controller, in your def Recipe action.
PS: Controller actions should be lowercase, so def recipe.
Related
I am trying to call a method in view template from its respective controller which is acting weirdly based on different conditions.
PLease note I have tried this after getting failure on this
Triply nested model's form in rails showing error
First of all the controller method is defined as ->
helper_method :find_feature
def find_feature(fid)
#project.features.find(fid)
end
And the view file code where this method is called ->
<% #project.features.each do |fet| %>
<%= "#{fet.name} #{fet.id} " %> #It does work!!
<%= render partial: "taskform",locals: { fetr: find_feature(fet.id) } %>
<% end %>
This throws error as Couldn't find Feature without an ID
in the screenshot islt is shown params[:id] is used that is not right sorry for that I have used the method which is written above as find_feature(fid) very sorry I will update the screenshot once I get to my mqchine
**
the error shows Couldn't find a feature without an id when called by find_feature(fet.id)
**
BUt when I explicitly test with an id, manually, like->
<%= render partial: "taskform", locals: { fetr: find_feature(7) } %>
This works !
Full stack trace-
activerecord (5.2.3) lib/active_record/relation/finder_methods.rb:433:in `find_with_ids'
activerecord (5.2.3) lib/active_record/relation/finder_methods.rb:69:in `find'
activerecord (5.2.3) lib/active_record/associations/collection_association.rb:100:in `find'
activerecord (5.2.3) lib/active_record/associations/collection_proxy.rb:140:in `find'
app/controllers/projects_controller.rb:7:in `find_feature'
actionpack (5.2.3) lib/abstract_controller/helpers.rb:67:in `find_feature'
app/views/projects/show.html.erb:66:in `block in _app_views_projects_show_html_erb__3383934460746758134_70317115637280'
activerecord (5.2.3) lib/active_record/relation/delegation.rb:71:in `each'
activerecord (5.2.3) lib/active_record/relation/delegation.rb:71:in `each'
app/views/projects/show.html.erb:56:in `_app_views_projects_show_html_erb__3383934460746758134_70317115637280'
actionview (5.2.3) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.3) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.3) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.3) lib/action_view/template.rb:157:in `render'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.3) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.3) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.3) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.3) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.3) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.3) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.3) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.3) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/ayan/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (5.2.3) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:45:in `render'
actionpack (5.2.3) lib/action_controller/metal/implicit_render.rb:35:in `default_render'
actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.3) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'
omniauth (1.9.0) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.0) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.0) lib/omniauth/builder.rb:64:in `call'
rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.7) lib/rack/etag.rb:25:in `call'
rack (2.0.7) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.7) lib/rack/head.rb:12:in `call'
actionpack (5.2.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Request
Parameters:
{"id"=>"4"}
Can anyone suggests what is the reason of this behaviour ?
You are calling the find_feature with this code find_feature(fet.id), so you want to pass the id as a parameter.
Define the helper_method this way then:
def find_feature(fid)
#project.features.find(fid)
end
params[:fid] will look for a request parameter with the key fid in the request's params hash, you are passing a specific value to the method when you call it.
EDIT: Anyway, I'm not sure why are you doing that, you already have the feature object on the fet variable inside the loop, just do this:
<%= render partial: "taskform",locals: { fetr: fet } %>
error shows method calling with parmas[:fid], but you defined method as find_feature(fid) for finding feature , so there must be other method which is overriding , try it by giving different name like find_project_features it will work
Rails 5 application with will_paginate has the following log entry:
Usercontent Load (0.7ms) SELECT "usercontents".* FROM "usercontents" WHERE (id IN (171,172,33,34,35,156,173,144,78,81,88,90,93,96,36,37,38,48,87,89,94,39,175,176) AND contenttype_id = 1)
↳ app/controllers/travels_controller.rb:45
and the controller action specifies
#points = Usercontent.where('id IN (?) AND contenttype_id = ?', #all_valid_usercontents, 1).paginate(page: params[:page], per_page: 18)
if I run in the console that line as
#points = Usercontent.where('id IN (?) AND contenttype_id = ?', [171,172,33,34,35,156,173,144,78,81,88,90,93,96,36,37,38,48,87,89,94,39,175,176], 1).paginate(page: 1, per_page: 18)
then
> #points.class
=> Usercontent::ActiveRecord_Relation
Inserting in the controller debugging points:
Rails.logger.info #a_points.class
Rails.logger.info #points.class
returns
Usercontent::ActiveRecord_Relation
Usercontent::ActiveRecord_Relation
View
<div id='yield_pcontent'>
<%= render 'points' %>
</div>
<div id="infinite-scrolling">
<%= will_paginate %>
</div>
partial _points.html.erb
<div id=points class='tableize'>
<%= render partial: 'point', collection: #points %>
</div>
How can will_paginate thus recognize helper <%= will_paginate %> as an array
undefined method `total_pages' for #<Array:0x00007f9a27d47718>
note: adding require 'will_paginate/array' does not change this behaviour
update
activerecord (5.2.3) lib/active_record/relation/delegation.rb:125:in `method_missing'
will_paginate (3.1.7) lib/will_paginate/view_helpers.rb:73:in `will_paginate'
will_paginate (3.1.7) lib/will_paginate/view_helpers/action_view.rb:33:in `will_paginate'
app/views/travels/_region_points.html.erb:5:in `_app_views_travels__region_points_html_erb__2375899185333558082_70150028432340'
actionview (5.2.3) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.3) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.3) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.3) lib/action_view/template.rb:157:in `render'
actionview (5.2.3) lib/action_view/renderer/partial_renderer.rb:344:in `block in render_partial'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.3) lib/action_view/renderer/partial_renderer.rb:333:in `render_partial'
actionview (5.2.3) lib/action_view/renderer/partial_renderer.rb:312:in `render'
actionview (5.2.3) lib/action_view/renderer/renderer.rb:49:in `render_partial'
actionview (5.2.3) lib/action_view/helpers/rendering_helper.rb:36:in `render'
app/views/travels/cc.html.erb:33:in `_app_views_travels_cc_html_erb___2132430413937746159_70149902220280'
actionview (5.2.3) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.3) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.3) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.3) lib/action_view/template.rb:157:in `render'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.3) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.3) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.3) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.3) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.3) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.3) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.3) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.3) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.3) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.3) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/jerdvo/.rbenv/versions/2.6.1/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (5.2.3) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:45:in `render'
wicked_pdf (1.2.2) lib/wicked_pdf/pdf_helper.rb:46:in `call'
wicked_pdf (1.2.2) lib/wicked_pdf/pdf_helper.rb:46:in `render_with_wicked_pdf'
wicked_pdf (1.2.2) lib/wicked_pdf/pdf_helper.rb:30:in `render'
app/controllers/travels_controller.rb:59:in `cc'
actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.3) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.7) lib/rack/etag.rb:25:in `call'
rack (2.0.7) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.7) lib/rack/head.rb:12:in `call'
actionpack (5.2.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:22:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
Update 2
based on a suggestion, two behaviours are being observed:
<%= will_paginate %> => undefined method `total_pages' for #<Array:0x00007f9a261e2540>
<%= will_paginate #points %> => undefined method `total_pages' for #<Usercontent::ActiveRecord_Relation:0x00007f9a26d07ab0>
He is waiting for an Object, not an Array. I share my solution, adapt it to your case.
def render_partial_resource(resources)
if resources.present?
if resources.respond_to?(:model_name)
folder = resources.model_name.name.pluralize.downcase
partial = resources.model_name.name.downcase
else
folder = resources.object.name.pluralize.downcase
partial = resources.object.name.downcase
end
resources.map do |resource|
render partial:"#{folder}/#{partial}", locals:{"#{partial}": resource}
end.join(" ").html_safe
end
end
NameError Link I'm try to launch my ruby application using rails server . Prior to that I used $ rails generate controller simple_pages index. The error is generated saying NameError in SimplePages#index on http://localhost:3000/
Tried checking the index.html.erb and application.html.erb files along with routes.rb file under config folder
routes.rb
Rails.application.routes.draw do
root 'simple_pages#index'
get 'index', to: 'simple_pages#index'
end
index.html.erb
<!DOCTYPE html>
<html>
<head>
<title>R2</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<nav>
<ul>
<li><%= link_to "Home",root_path %></li>
<li><%= link_to "About",simple_pages_about_path %></li>
<li><%= link_to "Contact",simple_pages_contact_path %></li>
</ul>
</nav>
<%= yield %>
</<footer>
© 2018 Bike Berlin
</footer>
</body>
</html>
application.html.erb
<p id="notice"><%= notice %></p>
<h1>Simple Pages</h1>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #simple_pages.each do |simple_page| %>
<tr>
<td><%= link_to 'Show', simple_page %></td>
<td><%= link_to 'Edit', edit_simple_page_path(simple_page) %></td>
<td><%= link_to 'Destroy', simple_page, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Simple Page', new_simple_page_path %>
The page should display no errors.
Stack trace as follows
app/views/simple_pages/index.html.erb:25:in _app_views_simple_pages_index_html_erb___2005229969295768109_70270503512740'
actionview (5.2.2) lib/action_view/template.rb:159:in 'block in render'
activesupport (5.2.2) lib/active_support/notifications.rb:170:in 'instrument'
actionview (5.2.2) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.2) lib/action_view/template.rb:157:in `render'
actionview (5.2.2) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.2) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.2) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.2) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.2) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.2) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.2) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.2) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.2) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.2) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.2) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.2) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.2) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.2) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.2) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.2) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.2) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/saishbhende24/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (5.2.2) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.2) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:45:in `render'
actionpack (5.2.2) lib/action_controller/metal/implicit_render.rb:35:in `default_render'
actionpack (5.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (5.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (5.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.2) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.2) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.2) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.2) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.2) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.2) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.2) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.2) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.2) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.2) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.2) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.2) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.2) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.2) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack (2.0.6) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.6) lib/rack/etag.rb:25:in `call'
rack (2.0.6) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.6) lib/rack/head.rb:12:in `call'
actionpack (5.2.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.6) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.6) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.2) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.6) lib/rack/method_override.rb:22:in `call'
rack (2.0.6) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
railties (5.2.2) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
You don't have a corresponding route/helper (from what we can see). You need to do this in your routes.rb
resources :simple_pages
Follow below steps:
rails g controller simple_pages
# in your routes file
root 'simple_page#index'
resources :simple_pages
# in your controllers
class SimplePageController < ApplicationController
def index
end
end
Replace the following in routes.rb get 'simple_pages/index' wrong get 'index', to: 'simple_pages#index' should be like this
I'm developing a system to improve my Rails skills, which will allow anyone to create a user. This user will have an inventory, which will contain multiple items.
My question is how can I store all the resources when saving a new user. I'm trying to use cocoon gem, and I got this error message:
undefined method `new_record?' for nil:NilClass
at this part of the code:
<%= link_to_remove_association "remove item", f %>
Models
class User < ActiveRecord::Base
has_one :inventory
delegate :items, to: :inventory, prefix: true
accepts_nested_attributes_for :inventory
end
class Inventory < ActiveRecord::Base
has_many :inventory_items
has_many :items, through: :inventory_items
accepts_nested_attributes_for :inventory_items, reject_if: :all_blank, allow_destroy: true
end
class InventoryItem < ActiveRecord::Base
belongs_to :item
belongs_to :inventory
end
Controller
class UsersController < ApplicationController
def new
#user = User.new.tap do |user|
user.inventory = Inventory.new
user.inventory_items.build
end
end
private
def user_params
params
.require(:user)
.permit(
:name,
:lat,
:long,
:age,
inventory_attributes: [:id, inventory_items_attributes: [:quantity, :inventory_id, :item_id, :_destroy]]
)
end
end
User form
<%= simple_form_for(#user) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :lat %>
<%= f.input :long %>
</div>
<h3>Items</h3>
<div id="inventory_items">
<%= f.simple_fields_for :inventory do |inventory| %>
<%= inventory.simple_fields_for :inventory_items do |f| %>
<%= render 'item_fields', f: f %>
<% end %>
<% end %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
item_fields partial
<div class="nested-fields">
<%= f.collection_select :item_id, Item.all, :id, :name %>
<%= f.input :quantity %>
<%= link_to_remove_association "remove item", f %>
</div>
The inventory does not have more attributes than its id and user_id
Stack trace
cocoon (1.2.9) lib/cocoon/view_helpers.rb:29:in `link_to_remove_association'
app/views/users/_inventory_item_fields.html.erb:6:in `_app_views_users__inventory_item_fields_html_erb__1201857070210368281_70056778972140'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:309:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.2.4) lib/action_view/helpers/rendering_helper.rb:35:in `render'
app/views/users/new.html.erb:12:in `block (3 levels) in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:714:in `fields_for'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1599:in `fields_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/builder.rb:27:in `simple_fields_for'
app/views/users/new.html.erb:11:in `block (2 levels) in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1925:in `block in fields_for_nested_model'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:714:in `fields_for'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1924:in `fields_for_nested_model'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1914:in `fields_for_with_nested_attributes'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1582:in `fields_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/builder.rb:27:in `simple_fields_for'
app/views/users/new.html.erb:10:in `block in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:444:in `form_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:26:in `block in simple_form_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:45:in `with_simple_form_field_error_proc'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:25:in `simple_form_for'
app/views/users/new.html.erb:1:in `_app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.4) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.4) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.4) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.4) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/vinicius/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.4) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
I'm trying to render partials from another view posts/_index and posts/_new and controller Posts, into another view welcome/index. The posts/_index loads fine, but I can't figure out/understand why the posts/_new throws an error for the :text method which is only defined in the database migration, which I thought would be universally accessible.
This is where it references the error in the welcome/_new partial:
<%= form_for :post, url: posts_path do |f| %>
<p id="post_box">
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
And this is the working posts/_index partial:
<% post.reverse.each do |post| %>
<div class="panel panel-default">
<div class="panel-body">
<%= post.text %>
</div>
</div>
<% end %>
For reference the code is the same as: Why aren't instance variables defined in a controller's methods available in the corresponding partials?
except controllers/welcome_controller.rb
class WelcomeController < ApplicationController
def new
end
def index
#post = Post.all
end
private
def post_params
params.require(:post).permit(:text)
end
end
Full trace:
app/views/posts/_index.html.erb:1:in `_app_views_posts__index_html_erb__2553516224846921857_70315677910360'
actionview (4.1.7) lib/action_view/template.rb:145:in `block in render'
activesupport (4.1.7) lib/active_support/notifications.rb:161:in `instrument'
actionview (4.1.7) lib/action_view/template.rb:339:in `instrument'
actionview (4.1.7) lib/action_view/template.rb:143:in `render'
actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:306:in `render_partial'
actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:279:in `block in render'
actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `instrument'
actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:278:in `render'
actionview (4.1.7) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.1.7) lib/action_view/renderer/renderer.rb:21:in `render'
actionview (4.1.7) lib/action_view/helpers/rendering_helper.rb:32:in `render'
app/views/welcome/index.html.erb:118:in `_app_views_welcome_index_html_erb___2498066675045436064_70315678370540'
actionview (4.1.7) lib/action_view/template.rb:145:in `block in render'
activesupport (4.1.7) lib/active_support/notifications.rb:161:in `instrument'
actionview (4.1.7) lib/action_view/template.rb:339:in `instrument'
actionview (4.1.7) lib/action_view/template.rb:143:in `render'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `instrument'
actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionview (4.1.7) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.1.7) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.1.7) lib/action_view/rendering.rb:99:in `_render_template'
actionpack (4.1.7) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.1.7) lib/action_view/rendering.rb:82:in `render_to_body'
actionpack (4.1.7) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.1.7) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
actionpack (4.1.7) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.1.7) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.1.7) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (4.1.7) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.1.7) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.1.7) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.1.7) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.7) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.7) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.7) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.7) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.7) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.7) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.7) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.7) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.7) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.7) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.7) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.7) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.7) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.7) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.7) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.7) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.7) lib/action_dispatch/journey/router.rb:73:in `block in call'
actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:678:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.7) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.7) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.7) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.7) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.7) lib/rails/engine.rb:514:in `call'
railties (4.1.7) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
The issue here is you are trying to print the text of all the posts, the text is attribute of single post.. That' why it's unable to find, 'text' attribute of association result(Post.all).
def index
#posts = Post.all
end
#index.html.erb
<% #posts.each do |post| %>
<%= post.text %>
<% end %>
Assuming you are trying to list all the posts & create a new post being in the welcome/index, you need to modify your index action like this :
def index
#posts = Post.all #this one to list posts
#post = Post.new #this initializer will be used in your _new partial.
end