I've set up the impressionist gem in my Film model. It has been working fine, updating the impressions count, but suddenly I've been receiving the following error when trying to GET the Films#Show page.
undefined method `cookie_value' for "60cb104e4befe185a8b81aac9a2c5e3c":String
It seems like it has something to do with the session_hash, but not sure how to solve this issue.
Does anyone have any ideas?
Here is my Film model:
class Film < ApplicationRecord
acts_as_votable
is_impressionable
mount_uploader :cover, ImageUploader
mount_uploader :video, VideoUploader
mount_uploader :trailer, VideoUploader
def score
self.get_upvotes.size - self.get_downvotes.size
end
extend FriendlyId
friendly_id :title, use: :slugged
# one film has many reviews
has_many :reviews, dependent: :destroy
validates :title, presence: true
validates :author, presence: true
validates :cover, presence: true
validates :description, presence: true
end
Films show page
<%= render "shared/ticker" %>
<div class="back-to-films">
<%= link_to films_path do %>
<span><%= image_tag "BackArrow1.svg" %> </span><h3 class="back-to-gallery">Back to film gallery</h3>
<% end %>
</div>
<section class="film-show-grid">
<div class="film-show-img" onclick="toggle();">
<%= image_tag #film.cover.show.url %>
</div>
<div class="film-show-info">
<span><% if #film.is_top_pick %>
<%= image_tag "is_featured.svg", :class => "top-pick-show" %>
<% end %></span>
<span class="liking-target">
<%= link_to like_film_path(#film), class: "upvoted {liked_or_not}", method: :put, remote: :true do %>
<%= image_tag "Polygon2.svg", :class => "polygon" %>
<% end %>
<span class="like_count">
<%= #film.get_likes.size %>
</span>
</span>
<span class="views">
<%= image_tag "view.svg", :class => "eyeball" %>
<span class="impressions"><%= #film.impressionist_count(:filter=>:ip_address) %></span>
</span>
<div class="">
<h2 class="film-title"><%= #film.title %></h2>
<h6 class="film-author"><%= #film.author %></h6> <span><%= #film.description %></span>
<p class="film-description"><%= #film.description_body %></p>
</div>
<div class="play-button" onclick="toggle();">
<span> Play </span> <%= image_tag "play.svg", :class => "play-symbol" %>
</div>
<div class="preview-button" onclick="toggleTrailer();">
Trailer
</div>
<%= link_to film_reviews_path(#film) do %>
<div class="cafe-talk-button">
Café talk
</div>
<% end %>
And my full stack trace
impressionist (2.0.0) app/controllers/impressionist_controller.rb:143:in `session_hash'
impressionist (2.0.0) app/controllers/impressionist_controller.rb:60:in `associative_create_statement'
impressionist (2.0.0) app/controllers/impressionist_controller.rb:27:in `impressionist'
app/controllers/films_controller.rb:28:in `show'
actionpack (6.0.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.2) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.2) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.3.2) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.2) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.2) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.2) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.2) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.3.2) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.3.2) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.3.2) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.3.2) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.0.3.2) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:834: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.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (6.0.3.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.3.2) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.4) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.4) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.2) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.2) 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.3.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/host_authorization.rb:82: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.3.2) lib/rails/engine.rb:527:in `call'
puma (4.3.5) lib/puma/configuration.rb:228:in `call'
puma (4.3.5) lib/puma/server.rb:713:in `handle_request'
puma (4.3.5) lib/puma/server.rb:472:in `process_client'
puma (4.3.5) lib/puma/server.rb:328:in `block in run'
puma (4.3.5) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
I updated a legacy Rails application that is using the impression gem to version 6 and ran into the same exception. I worked around it by specifying a specific commit for the impression gem in the Gemfile:
gem 'impressionist',
git: 'git#github.com:charlotte-ruby/impressionist.git',
ref: '46a582ff8cd3496da64f174b30b91f9d97e86643'
The reason for this is that the fix for the exception is not in their latest release (2.0.0) but is in its master branch.
Related
I have a form:
<%= form_tag generate_report_path(:header => true) do |f| % >
<div class="container-fluid">
<div style="padding-right:10px">
<%= select_tag(:report_id, options_for_select(
[["Select Report Type", 0],
["Report1", 1],
["Report2", 2],
["Report3", 3]]), id: "report_selection") %>
<%= hidden_field_tag :format, :pdf %>
I have a submit button and a checkbox right next to it:
<%= button_tag "Generate Report", class: 'btn btn-sm btn-primary'%>
<%= label_tag do %>
<%= check_box_tag "format_reqd", "format_reqd", false %>
Check for Numeric format
<% end %>
When the user selects the checkbox and clicks on the Generate Report button, I would like to display an alert to the user "your report would be emailed to you in a few minutes"; but the page should not be refreshed.
How can I achieve these two:
Disable page refresh?
Display a flash message?
Please help!
UPDATE:
I added this to my controller (called report_controller):
def reportgen
respond_to do |format|
format.js { flash.now[:alert] = "Report generation has been initiated. You will receive an email in approximately 4 - 5 minutes with a link to download the report."}
end
end
\app\views\report\reportgen.js.erb
$("#flash").html('<%= j render partial: "shared/notice_banner" %>');
application.html.erb
<div id="flash">
<% if alert.present? %>
<%= render partial: "shared/notice_banner" %>
<% end %>
</div>
<% flash.each do |key, value| %>
<% if key.to_s == "alert" %>
<div style= "color: #FF0000" class="text-center <%= flash_class(key) %>">
<%= value %>
</div>
<% else %>
<div class="lead text-center <%= flash_class(key) %>">
<%= value %>
</div>
<% end %>
<% end %>
<%= yield %>
app\views\shared\_notice_banner.html.erb
<div data-alert class="alert-box">
<%= alert %>
×
</div>
And this is my code to add the button and checkbox in my form:
<div id="generate_button" style="display: none; float:left;">
<%= button_tag "Generate Report", class: 'btn btn-sm btn-primary'%>
</div>
<div id="report_type_drop" style="display: none;padding-top:5px;padding-left:5px">
<%= label_tag do %>
<%= check_box_tag "format_reqd", "format_reqd", false %>
Check for Numeric format
<% end %>
</div>
With the above code these are the results for my 2 issues in my original question right now:
Disable page refresh - this works perfectly fine now
Display flash message - this does not work!
UPDATE:
I also see this error now (not sure what's causing this though):
ActionController::UnknownFormat (ReportController#reportgen is missing a template for this request format and variant.
request.formats: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
request.variant: []):
actionpack (5.0.7.1) lib/action_controller/metal/implicit_render.rb:43:in `default_render'
actionpack (5.0.7.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
actionpack (5.0.7.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
actionpack (5.0.7.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.7.1) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.7.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.7.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
audited (4.8.0) lib/audited/sweeper.rb:14:in `around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:405:in `public_send'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:405:in `block in make_lambda'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:285:in `block in halting'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:447:in `block in around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
audited (4.8.0) lib/audited/sweeper.rb:14:in `around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:405:in `public_send'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:405:in `block in make_lambda'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:285:in `block in halting'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:447:in `block in around'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.7.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.7.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.7.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.7.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.7.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.7.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.7.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.7.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.7.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.7.1) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.7.1) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.7.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.7.1) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.7.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.7.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.7.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.7.1) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.7.1) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.7.1) lib/action_dispatch/routing/route_set.rb:727:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
omniauth (1.4.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.4.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/etag.rb:25:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/conditional_get.rb:38:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/head.rb:12:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99: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'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
activerecord (5.0.7.1) lib/active_record/migration.rb:553:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.7.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.7.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99: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'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
railties (5.0.7.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.7.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.7.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.7.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.7.1) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.7.1) lib/rails/rack/logger.rb:24:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/method_override.rb:22:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
activesupport (5.0.7.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
actionpack (5.0.7.1) lib/action_dispatch/middleware/static.rb:136:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
railties (5.0.7.1) lib/rails/engine.rb:522:in `call'
newrelic_rpm (6.3.0.355) lib/new_relic/agent/instrumentation/middleware_tracing.rb:99: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'
UPDATE: (update 3)
If I change my controller code to this:
the above stacktrace error goes away
page refresh does not happen - this is good
but the flash message still does not appear
respond_to do |format|
format.json { flash.now[:alert] = "Report generation has been initiated. You will receive an email in approximately 4 - 5 minutes with a link to download the report."}
end
You should use remote: true in your form.
<%= form_tag generate_report_path(:header => true), remote: true do |f| % >
<div class="container-fluid">
<div style="padding-right:10px">
<%= select_tag(:report_id, options_for_select(
[["Select Report Type", 0],
["Report1", 1],
["Report2", 2],
["Report3", 3]]), id: "report_selection")
%>
<%= hidden_field_tag :format, :pdf %>
<%= button_tag "Generate Report", class: 'btn btn-sm btn-primary'%>
<%= label_tag do %>
<%= check_box_tag "format_reqd", "format_reqd", false %>
Check for Numeric format
<% end %>
<% end %>
Above remote: true is responsible for sending ajax request to your
controller method. Here is a complete guide for form_for and remote
requests.
In your method of the controller:
def generate_report
... #Whatever you want to add here.
render js: "alert('Your report would be emailed to you in a few minutes')"
end
Update with the flash message:
Your controller method will now look like:
def generate_report
... #Whatever you want to add here.
respond_to do |format|
format.js { flash[:notice] = "Your report would be emailed to you in a few minutes" }
end
end
Rendered view:
# app/views/users/generate_report.js.erb
$("#flash").html('<%= j render partial: "shared/notice_banner" %>');
# app/views/layouts/application.html.erb
<div id="flash">
<% if notice.present? %>
<%= render partial: "shared/notice_banner" %>
<% end %>
</div>
# app/views/shared/_notice_banner.html.erb
<div data-alert class="alert-box">
<%= notice %>
×
</div>
Here is the detailed answer present.
Hope this will help.
I'm having some trouble with nested attributes when the defined classes are inside a module:
# file bar.rb
module Abc
class Bar << ActiveRecord::Base
has_many :foos
accepts_nested_attributes_for :foos
end
end
# file foo.rb
module Abc
class Foo << ActiveRecord::Base
belongs_to :bar
# let's consider an attribute: qux
end
end
# inside the controller
def new
#bar = Abc::Bar.new
end
# inside a view
<%= form_for #bar .... do |f| %>
....
<%= f.fields_for :abc_foos, #bar.foos do |ff| %>
<%= ff.hidden_field :qux, value: true %>
<% end %>
<% end %>
Now we got the prefix "abc" in the names attributes>
# the rendered html
<input type="hidden" name="abc_bar[abc_foos][qux]" ... />
The params now comes with the abc_foos included:
# the params hash
"abc_bar" => {
....
"abc_foos" => {"qux" => "some value"}
}
The problem: the accepts_nested_attributes_for method creates something like "abc_foos_attributes=" in order to receive the attributes, but the default param key name is different. So, this will not work:
# in the controller, again
def create
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, abc_foos: [:qux]))
end
I get the error:
unknown attribute 'abc_foos' for Abc::Bar.
I would expect something like "foos_attributes" as the appropriate key. What am I missing?
Thanks!
The full bactrace:
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:53:in `_assign_attribute'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `block in assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `each'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:25:in `_assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (5.2.1) lib/active_record/core.rb:314:in `initialize'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
app/controllers/bar_controller.rb:33:in `create'
actionpack (5.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.1) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.1) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.1) 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:38:in `call'
rack (2.0.6) lib/rack/head.rb:12:in `call'
actionpack (5.2.1) 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.1) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.1) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) 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.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.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 (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.1) 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.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) 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'
Can you post full backtrace errors? But in the meantime if you try
<%= f.fields_for :foos, #bar.foos do |foo| %>
<%= foo.hidden_field :qux, value: true %>
<% end %>
you probably also need to do
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, foos: [:qux]))
I just switched my app from a hand-made login system to use the Devise gem. I have used this gem with many apps before, but have never had this issue. All the views are implemented correctly and display when they should, but when I try to create a new registration I get the following error:
ActionController::UnknownFormat in RegistrationsController#create
The trace it gives is as follows:
responders (2.2.0) lib/action_controller/respond_with.rb:207:in `respond_with'
devise (4.2.0) app/controllers/devise/registrations_controller.rb:32:in `create'
actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.6) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.6) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.6) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.6) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.6) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.6) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.6) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.6) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.6) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.6) 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.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.6) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.6) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.6) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.6) 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.6) 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.6) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.6) lib/rails/engine.rb:518:in `call'
railties (4.2.6) 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'
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
When I attempt to log in, I also get a blank white screen that just says "You need to sign in or sign up before continuing."
I think these errors are related, but as I have had no experience with this set of errors with Devise I'm not 100% sure. Can anyone help me figure out what's going wrong here?
ADDITIONAL INFORMATION
Here's the code for registrations#new:
<div class="hero-image-row">
<div class="hero-image-outer text-center">
<div class="hero-image-inner text-center">
<%= image_tag 'Background 17.jpg', class: "hero-image",alt: "Beautiful golf hole by the ocean" %>
</div> <!-- hero-image-inner -->
</div> <!-- hero-image-inner -->
</div> <!-- row -->
<div class="overlap-hero-image">
<div class="buffer-25"></div>
<div class="buffer-50"></div>
<div class="container">
<div class="container text-center col-xs-10 col-xs-push-1" style="background-color: rgba(235, 235, 235, 0.8) !important">
<h1 style="color: black">Sign Up</h1>
<%= simple_form_for(resource, as: resource_name, url: user_registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs text-left row">
<div class="col-sm-12">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="col-sm-6">
<%= f.input :password, required: true, hint: ("#{#minimum_password_length} characters minimum" if #minimum_password_length) %>
</div>
<div class="col-sm-6">
<%= f.input :password_confirmation, required: true %>
</div>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div> <!-- columns box -->
</div> <!-- container -->
</div> <!-- overlap-tall-hero-image -->
Here's a supplemental registrations_controller for some added columns:
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :gender, :birthday, :dom_hand, :sport, :g_years, :g_rounds, :g_practice, :handicap, :g_score, :admin)
end
def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :gender, :birthday, :dom_hand, :sport, :g_years, :g_rounds, :g_practice, :handicap, :g_score, :admin)
end
end
And here's how it's reflected in my routes:
devise_for :users, :controllers => { registrations: 'registrations' }
It turned out that Devise autogenerated this for both registrations#new and sessions#new:
<%= simple_form_for(resource, as: resource_name, url: user_registration_path(resource_name)) do |f| %>
The error disappeared when I removed (resource_name) on each form.
I want to add images as attachment to comments. Comments belong to a Post. I've looked at this gist. I've also tried with nested_form gem, but still the same error.
form
<%= semantic_form_for([#post, #comment], validate: true, html: {multipart: true}, 'data-update-target' => 'comments', class: 'comments') do |f| %>
<%= f.text_field :title %>
<%= f.semantic_fields_for :comment_images do |pic| %>
<%= pic.inputs do %>
<%= pic.hidden_field :id %>
<%= pic.hidden_field :attachable_id %>
<%= pic.hidden_field :attachable_type %>
<%= pic.file_field :image %>
<% end %>
<% end %>
...
comment_image model
class CommentImage < ActiveRecord::Base
belongs_to :attachable, polymorphic: true
attr_accessible :image, :attachable_id, :attachable_type
mount_uploader :image, ImageUploader
end
comment model
class Comment < ActiveRecord::Base
attr_accessor :image, :file
has_many :comment_images, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :comment_images, :allow_destroy => true
server log
Started GET "/posts/1/comments/new" for ....136 at 2014-04-28 16:41:47 +0000
Processing by CommentsController#new as HTML
Parameters: {"post_id"=>"1"}
Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
params********************{"action"=>"new", "controller"=>"comments", "post_id"=>"1"}
Completed 500 Internal Server Error in 9ms
NoMethodError - undefined method `[]' for nil:NilClass:
activerecord (4.0.4) lib/active_record/attribute_methods/read.rb:86:in `block in read_attribute'
activerecord (4.0.4) lib/active_record/attribute_methods/read.rb:84:in `read_attribute'
activerecord (4.0.4) lib/active_record/attribute_methods.rb:344:in `[]'
activerecord (4.0.4) lib/active_record/associations/association_scope.rb:73:in `block in add_constraints'
activerecord (4.0.4) lib/active_record/associations/association_scope.rb:44:in `add_constraints'
activerecord (4.0.4) lib/active_record/associations/association_scope.rb:19:in `scope'
activerecord (4.0.4) lib/active_record/associations/association.rb:103:in `association_scope'
activerecord (4.0.4) lib/active_record/associations/association.rb:87:in `scope'
activerecord (4.0.4) lib/active_record/associations/collection_association.rb:382:in `scope'
activerecord (4.0.4) lib/active_record/associations/collection_proxy.rb:37:in `initialize'
activerecord (4.0.4) lib/active_record/relation/delegation.rb:78:in `new'
activerecord (4.0.4) lib/active_record/associations/collection_association.rb:37:in `reader'
activerecord (4.0.4) lib/active_record/associations/builder/association.rb:70:in `comment_images'
app/controllers/comments_controller.rb:18:in `new'
actionpack (4.0.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.4) lib/active_support/callbacks.rb:433:in `_run__1580909207748771124__process_action__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.4) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:674:in `call'
omniauth (1.2.1) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.1) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.1) lib/omniauth/builder.rb:59:in `call'
meta_request (0.3.0) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.3.0) lib/meta_request/middlewares/headers.rb:16:in `call'
meta_request (0.3.0) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
newrelic_rpm (3.8.0.218) lib/new_relic/rack/error_collector.rb:55:in `call'
newrelic_rpm (3.8.0.218) lib/new_relic/rack/agent_hooks.rb:32:in `call'
newrelic_rpm (3.8.0.218) lib/new_relic/rack/browser_monitoring.rb:27: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.0.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/flash.rb:241: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.0.4) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.4) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.4) lib/active_support/callbacks.rb:373:in `_run__2395107169417203351__call__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.4) 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.0.4) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.4) lib/rails/engine.rb:511:in `call'
railties (4.0.4) lib/rails/application.rb:97: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'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
The problem was with
attr_accessible :image, :attachable_id, :attachable_type
I had 'protected_attributes' gem, but I still had to create controller with strong_parameters instead to make it work. More info here.
Ive been doing some research and I can't seem to find what Im doing wrong.
I have installed simple_form and nested_form gems but when I use either link_to_add or remove I get the same error.
Heres the code
/fields.html.erb
<%= render 'shared/error_messages', :object => f.object %>
<%= f.input :nombre_cliente, :label => 'Nombre del cliente:', :as => :string %>
<%= f.input :mail_cliente, :label => 'E-mail del cliente:', :as => :string %>
<%= f.input :empresa_cliente, :label => 'Empresa:', :as => :string %>
<%= f.input :confirmada, :label => 'Ha sido confirmada por el cliente.' %>
<%= f.input :confirmacion_cliente, :label => 'Fecha de confirmacion por el cliente:', :as => :date %>
<b>something here</b>
</br></br>
<%= f.simple_fields_for :producto_de_cotizacion do |productos| %>
<%= productos.input :nombre %>
<%= productos.input :descripcion %>
<%= productos.input :precio%>
<%= productos.link_to_remove("Eliminar producto") %>
<% end %>
<%= f.link_to_add "Agregar producto", :producto_de_cotizacion %>
Some of it is in spanish but I think its understandable
Here is the actual error Im getting:
undefined method `link_to_remove' for < SimpleForm::FormBuilder:0x9ccf37c>
That is the entirety of _fields.html.erb, but its being called by the new.html.erb and the edit.html.erb files which are basically identical, Ill post the edit file:
<h1>Agregar Cotizacion</h1>
<div id='admin_view'>
<%= simple_form_for #cotizacion, :html => {:multipart => true} do |f| %>
<%= render "fields", :f => f %>
<%= f.button :submit, 'Actualizar Cotizacion' %>
<% end%>
</div>
After changing it to simple_nested_form I get a new error:
undefined method `klass' for nil:NilClass
and heres the stack
activesupport (3.0.7) lib/active_support/whiny_nil.rb:48:in `method_missing'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/builder_mixin.rb:23:in `block in link_to_add'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:37:in `call'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:37:in `block in after_nested_form_callbacks'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:36:in `map'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:36:in `after_nested_form_callbacks'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:13:in `simple_nested_form_for'
app/views/cotizacions/edit.html.erb:3:in `_app_views_cotizacions_edit_html_erb__855809706_86735240_354753338'
actionpack (3.0.7) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.7) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.7) lib/action_view/template.rb:127:in `render'
actionpack (3.0.7) lib/action_view/render/rendering.rb:59:in `block in _render_template'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.7) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.7) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:39:in `render'
meta-tags (1.2.4) lib/meta_tags/controller_helper.rb:28:in `render_with_meta_tags'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:14:in `default_render'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:6:in `send_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.7) lib/active_support/callbacks.rb:451:in `_run__761686272__process_action__750077467__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.7) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
warden (0.10.7) lib/warden/manager.rb:35:in `block in call'
warden (0.10.7) lib/warden/manager.rb:34:in `catch'
warden (0.10.7) lib/warden/manager.rb:34:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.7) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.4) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.7) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.7) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.7) lib/rails/application.rb:168:in `call'
railties (3.0.7) lib/rails/application.rb:77:in `method_missing'
railties (3.0.7) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.4) lib/rack/content_length.rb:13:in `call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:in `service'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Use :locals => { :f => f }
EDIT: Changing my answer.
I just realized you are using:
simple_form_for
Change that to
simple_nested_form_for
This allows you to use the nested_form options (link_to_add, link_to_remove, etc).
Cheers!
So I changed the new.html.erb and edit.html.erb to look like this:
<h1>Agregar Cotizacion</h1>
<div id='admin_view'>
<%= simple_nested_form_for #cotizacion, :html => {:multipart => true} do |f| %>
<%= render 'fields', :f => f %>
<%= f.button :submit, 'Agregar Cotizacion' %>
<% end%>
</div>
And I added this to the routes.rb file
resources :cotizacions do
resources :producto_de_cotizacions
end
resources :producto_de_cotizacions
Im not exactly sure how but this fixed the issue. Thanks a lot for your help. Cheers!
I have this error, solved by restarting server and adding this code to model:
accepts_nested_attributes_for :photos, :reject_if => :all_blank, :allow_destroy => true