Ruby on rails - wrong number of arguments (2 for 1) [Rails] - ruby-on-rails

I've just change my database from sqlite3 to postgresql in my Ruby on rails.
Every things worked before but now I have a "wrong number of arguments (2 for 1)" when I submit the form. I don't understand why !
Here my code :
my photo_controller file :
class PhotosController < ApplicationController
before_action :set_photo, only: [:show, :edit, :update, :destroy]
# GET /photos
# GET /photos.json
def index
#photos = Photo.all
end
# GET /photos/1
# GET /photos/1.json
def show
end
# GET /photos/new
def new
#photo = Photo.new
end
# GET /photos/1/edit
def edit
end
# POST /photos
# POST /photos.json
def create
#photo = Photo.new(photo_params)
respond_to do |format|
if #photo.save
format.html { redirect_to #photo, notice: 'Photo was successfully created.' }
format.json { render action: 'show', status: :created, location: #photo }
else
format.html { render action: 'new' }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /photos/1
# PATCH/PUT /photos/1.json
def update
respond_to do |format|
if #photo.update(photo_params)
format.html { redirect_to #photo, notice: 'Photo was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# DELETE /photos/1
# DELETE /photos/1.json
def destroy
#photo.destroy
respond_to do |format|
format.html { redirect_to photos_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_photo
#photo = Photo.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
params.require(:photo).permit(:image)
end
end
my photo.rb file :
class Photo < ActiveRecord::Base
has_attached_file :image
end
my new.html.erb file ( here is the form and after I chose the image and submit it, I have the error ) :
<h1>New photo</h1>
<%= form_for #photo, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.file_field :image %>
</div>
<div class="action">
<%= f.submit %>
</div>
<% end %>
my show.html.erb file :
<h1> Je viens de faire un upload ! </h1>
<% if #photo.image? %>
<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: ' f20374413e3ff5a8',
apiVersion: 3,
theme: 'light', // Check out our new 'light' and 'dark' themes!
tools: 'all',
appendTo: '',
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
},
onError: function(errorObj) {
alert(errorObj.message);
}
});
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src
});
return false;
}
</script>
<div id='injection_site'></div>
<img id='image1' src='<%= #photo.image.url %>'/>
<!-- Add an edit button, passing the HTML id of the image and the public URL of the image -->
<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('image1', '<%= #photo.image.url %>');" /></p>
<% end %>
Backtrace:
Application trace :
app/controllers/photos_controller.rb:27:in `create'
Full trace :
activesupport (4.0.0) lib/active_support/callbacks.rb:78:in `run_callbacks'
paperclip (3.0.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.0.4) lib/paperclip/attachment.rb:382:in `post_process'
paperclip (3.0.4) lib/paperclip/attachment.rb:106:in `assign'
paperclip (3.0.4) lib/paperclip.rb:194:in `block in has_attached_file'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/core.rb:192:in `initialize'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
app/controllers/photos_controller.rb:27:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__921501253494556441__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) 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.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__2330035833412540959__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) 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.0) 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.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) 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/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Please help me :)

Looks like you're seeing this error and you should just upgrade Paperclip to the latest version, 3.5.2.
You're running a pretty old paperclip anyway.

Just pulling out the essential pieces from above:
Error:
wrong number of arguments (2 for 1)
Source:
Controller:
1: class PhotosController < ApplicationController
...
24: # POST /photos
25: # POST /photos.json
26: def create
27: #photo = Photo.new(photo_params)
Model:
class Photo < ActiveRecord::Base
has_attached_file :image
end
View:
<%= form_for #photo, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.file_field :image %>
</div>
<div class="action">
<%= f.submit %>
</div>
<% end %>
Stacktrace:
Application trace :
app/controllers/photos_controller.rb:27:in `create'
Full trace :
activesupport (4.0.0) lib/active_support/callbacks.rb:78:in `run_callbacks'
paperclip (3.0.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.0.4) lib/paperclip/attachment.rb:382:in `post_process'
paperclip (3.0.4) lib/paperclip/attachment.rb:106:in `assign'
paperclip (3.0.4) lib/paperclip.rb:194:in `block in has_attached_file'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/core.rb:192:in `initialize'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
app/controllers/photos_controller.rb:27:in `create'

Related

NoMethodError - undefined method `file' for on simple query

I just want to show a picture but it always throws the same error. The join is correct but he doesn't show the image instead he throws that error.
Within the /series_images/ show and index the image is displayed with
<%= image_tag(#series_image.file, class: "img-responsive",) %>
That's working without any problems.
Here is the Server
Started GET "/series/beyond-the-boundary" for 127.0.0.1 at 2016-01-06 01:44:03 +0100
Processing by SeriesController#show as HTML
Parameters: {"id"=>"beyond-the-boundary"}
Series Load (0.3ms) SELECT "series".* FROM "series" WHERE "series"."slug" = $1 ORDER BY "series"."id" ASC LIMIT 1 [["slug", "beyond-the-boundary"]]
SeriesImage Load (0.3ms) SELECT "series_images".* FROM "series_images" WHERE "series_images"."series_id" = $1 [["series_id", 1]]
Rendered series/show.html.erb within layouts/application (3.4ms)
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.5ms)
NoMethodError - undefined method `file' for #<SeriesImage::ActiveRecord_Associations_CollectionProxy:0x007fc0e70be6e0>:
activerecord (4.2.5) lib/active_record/relation/delegation.rb:136:in `method_missing'
activerecord (4.2.5) lib/active_record/relation/delegation.rb:99:in `method_missing'
app/views/series/show.html.erb:2:in `_app_views_series_show_html_erb__1653679829410534096_70233272992260'
actionview (4.2.5) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.5) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.5) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.5) lib/action_view/template.rb:143:in `render'
actionview (4.2.5) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.5) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.5) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.5) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.5) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.5) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.5) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.5) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.5) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.5) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.5) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.5) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.5) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.5) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.2.5) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/woorari/.rbenv/versions/2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.5) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.5) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
warden (1.2.4) lib/warden/manager.rb:35:in `block in call'
warden (1.2.4) 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:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.5) 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.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.5) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) 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.5) 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.5) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) 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/woorari/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/woorari/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/woorari/.rbenv/versions/2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Started POST "/__better_errors/a376ff2bf7c7dd19/variables" for 127.0.0.1 at 2016-01-06 01:44:03 +0100
The call happen within the series/show.html.erb
<%= image_tag(#series.series_image.file, class: "img-responsive",) %>
<p>
<strong>Name:</strong>
<%= #series.name %>
</p>
Series Controller
class SeriesController < ApplicationController
before_action :set_series, only: [:show, :edit, :update, :destroy]
# GET /series
# GET /series.json
def index
#series = Series.paginate(:page => params[:page], :per_page => 10)
end
# GET /series/1
# GET /series/1.json
def show
end
# GET /series/new
def new
#series = Series.new
end
# GET /series/1/edit
def edit
end
# POST /series
# POST /series.json
def create
#series = Series.new(series_params)
respond_to do |format|
if #series.save
format.html { redirect_to #series, notice: 'Series was successfully created.' }
format.json { render :show, status: :created, location: #series }
else
format.html { render :new }
format.json { render json: #series.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /series/1
# PATCH/PUT /series/1.json
def update
respond_to do |format|
if #series.update(series_params)
format.html { redirect_to #series, notice: 'Series was successfully updated.' }
format.json { render :show, status: :ok, location: #series }
else
format.html { render :edit }
format.json { render json: #series.errors, status: :unprocessable_entity }
end
end
end
# DELETE /series/1
# DELETE /series/1.json
def destroy
#series.destroy
respond_to do |format|
format.html { redirect_to series_index_url, notice: 'Series was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_series
#series = Series.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def series_params
params.require(:series).permit(:name, :tagline, :shortDESC, :longDESC, :rating, :release)
end
end
SeriesImage Controller
class SeriesImagesController < ApplicationController
before_action :set_series_image, only: [:show, :edit, :update, :destroy]
# GET /series_images
# GET /series_images.json
def index
#series_images = SeriesImage.paginate(:page => params[:page], :per_page => 5)
end
# GET /series_images/1
# GET /series_images/1.json
def show
end
# GET /series_images/new
def new
#series_image = SeriesImage.new
end
# GET /series_images/1/edit
def edit
end
# POST /series_images
# POST /series_images.json
def create
#series_image = SeriesImage.new(series_image_params)
respond_to do |format|
if #series_image.save
format.html { redirect_to #series_image, notice: 'Series image was successfully created.' }
format.json { render :show, status: :created, location: #series_image }
else
format.html { render :new }
format.json { render json: #series_image.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /series_images/1
# PATCH/PUT /series_images/1.json
def update
respond_to do |format|
if #series_image.update(series_image_params)
format.html { redirect_to #series_image, notice: 'Series image was successfully updated.' }
format.json { render :show, status: :ok, location: #series_image }
else
format.html { render :edit }
format.json { render json: #series_image.errors, status: :unprocessable_entity }
end
end
end
# DELETE /series_images/1
# DELETE /series_images/1.json
def destroy
#series_image.destroy
respond_to do |format|
format.html { redirect_to series_images_url, notice: 'Series image was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_series_image
#series_image = SeriesImage.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def series_image_params
params.require(:series_image).permit(:series_id, :file, :desc, :head, :headID, :home, :homeID)
end
end
The 2 Models
class Series < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
validates :name, presence: true
has_many :series_images
end
class SeriesImage < ActiveRecord::Base
mount_uploader :file, PictureUploader
belongs_to :series
end
The gemfile
#better IDs
gem 'friendly_id', '~> 5.1'
#Bootstrap
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
#Image Upload
gem 'carrierwave', '~> 0.10.0'
#Bootswatch
gem 'bootswatch-rails', '~> 3.3', '>= 3.3.5'
# Devise User Management
gem 'devise', '~> 3.5', '>= 3.5.3'
#Pagination
gem 'will_paginate', '~> 3.1'
gem 'will_paginate-bootstrap', '~> 1.0', '>= 1.0.1'
The Migration of Series_Images
class CreateSeriesImages < ActiveRecord::Migration
def change
create_table :series_images do |t|
t.belongs_to :series, index:true
t.string :file
t.string :desc
t.boolean :head
t.integer :headID
t.boolean :home
t.integer :homeID
t.timestamps null: false
end
end
end
The problem is that you have a one to many relationship between Series and SeriesImages. So when you call #series.series_image in the view you are getting an active record collection back instead of a specific image. You could try doing #series.series_image.first.try(:file) and that would give you the first series_image if it exist. If this fails it will return nil.
Is a Series supposed to have multiple SeriesImages?

Carrierwave Gem cannot upload file in Rails

I have set up Carrierwave to upload pdf files to my datebase. I used my Gemfile to install after running bundle install. The problem is that when I try to create a new Object in the database, I get an error:
TypeError in BulletinsController#create
can't cast ActionDispatch::Http::UploadedFile to string
I believe I set everything up correctly but I would appreciate any advice that could be given. Here are my classes/models/controllers.
AttachmentUploader:
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Bulletin Model:
class Bulletin < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
end
Bulletins Controller:
class BulletinsController < ApplicationController
before_action :set_bulletin, only: [:show, :edit, :update, :destroy]
# GET /bulletins
# GET /bulletins.json
def index
#bulletins = Bulletin.all
end
# GET /bulletins/1
# GET /bulletins/1.json
def show
end
# GET /bulletins/new
def new
#bulletin = Bulletin.new
end
# GET /bulletins/1/edit
def edit
end
# POST /bulletins
# POST /bulletins.json
def create
#bulletin = Bulletin.new(bulletin_params)
respond_to do |format|
if #bulletin.save
format.html { redirect_to #bulletin, notice: 'Bulletin was successfully created.' }
format.json { render :show, status: :created, location: #bulletin }
else
format.html { render :new }
format.json { render json: #bulletin.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /bulletins/1
# PATCH/PUT /bulletins/1.json
def update
respond_to do |format|
if #bulletin.update(bulletin_params)
format.html { redirect_to #bulletin, notice: 'Bulletin was successfully updated.' }
format.json { render :show, status: :ok, location: #bulletin }
else
format.html { render :edit }
format.json { render json: #bulletin.errors, status: :unprocessable_entity }
end
end
end
# DELETE /bulletins/1
# DELETE /bulletins/1.json
def destroy
#bulletin.destroy
respond_to do |format|
format.html { redirect_to bulletins_url, notice: 'Bulletin was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_bulletin
#bulletin = Bulletin.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def bulletin_params
params.require(:bulletin).permit(:title, :text, :attachment)
end
end
And finally the bulletin new.html form:
<%= form_for #bulletin, :html => {:multipart => true} do |f| %>
<% if #bulletin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#bulletin.errors.count, "error") %> prohibited this bulletin from being saved:</h2>
<ul>
<% #bulletin.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :text %><br>
<%= f.text_area :text %>
</div>
<div class="field">
<%= f.label :attachment %><br>
<%= f.file_field :attachment %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
FULL TRACE:
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/quoting.rb:76:in `type_cast'
activerecord (4.1.1) lib/active_record/connection_adapters/sqlite3_adapter.rb:261:in `type_cast'
activerecord (4.1.1) lib/active_record/connection_adapters/sqlite3_adapter.rb:295:in `block in exec_query'
activerecord (4.1.1) lib/active_record/connection_adapters/sqlite3_adapter.rb:294:in `map'
activerecord (4.1.1) lib/active_record/connection_adapters/sqlite3_adapter.rb:294:in `exec_query'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:78:in `exec_insert'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:105:in `insert'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
activerecord (4.1.1) lib/active_record/relation.rb:64:in `insert'
activerecord (4.1.1) lib/active_record/persistence.rb:502:in `create_record'
activerecord (4.1.1) lib/active_record/attribute_methods/dirty.rb:87:in `create_record'
activerecord (4.1.1) lib/active_record/callbacks.rb:306:in `block in create_record'
activesupport (4.1.1) lib/active_support/callbacks.rb:82:in `run_callbacks'
activerecord (4.1.1) lib/active_record/callbacks.rb:306:in `create_record'
activerecord (4.1.1) lib/active_record/timestamp.rb:57:in `create_record'
activerecord (4.1.1) lib/active_record/persistence.rb:482:in `create_or_update'
activerecord (4.1.1) lib/active_record/callbacks.rb:302:in `block in create_or_update'
activesupport (4.1.1) lib/active_support/callbacks.rb:82:in `run_callbacks'
activerecord (4.1.1) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.1.1) lib/active_record/persistence.rb:103:in `save'
activerecord (4.1.1) lib/active_record/validations.rb:51:in `save'
activerecord (4.1.1) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.1.1) lib/active_record/transactions.rb:268:in `block (2 levels) in save'
activerecord (4.1.1) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
activerecord (4.1.1) lib/active_record/transactions.rb:208:in `transaction'
activerecord (4.1.1) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
activerecord (4.1.1) lib/active_record/transactions.rb:268:in `block in save'
activerecord (4.1.1) lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
activerecord (4.1.1) lib/active_record/transactions.rb:267:in `save'
app/controllers/bulletins_controller.rb:30:in `block in create'
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:433:in `call'
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:433:in `retrieve_collector_from_mimes'
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:256:in `respond_to'
app/controllers/bulletins_controller.rb:29:in `create'
actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.1) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.1) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.1) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.1) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.1) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.1.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.1) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.1.1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:676:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.1) 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.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.1) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.1) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.1) 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.1) 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.1) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.1) lib/rails/engine.rb:514:in `call'
railties (4.1.1) 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'
/usr/local/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"hCh2yJkRxNKW+z2ZOIISuAWu/2gRI++noacQxDnst78=",
"bulletin"=>{"title"=>"Test",
"text"=>"Testing123",
"attachment"=>#<ActionDispatch::Http::UploadedFile:0xc69d9b0 #tempfile=#<Tempfile:/tmp/RackMultipart20140619-13131-17crugy>,
#original_filename="test.pdf",
#content_type="application/pdf",
#headers="Content-Disposition: form-data; name=\"bulletin[attachment]\"; filename=\"test.pdf\"\r\nContent-Type: application/pdf\r\n">},
"commit"=>"Create Bulletin"

error when updating whilst using acts-as-taggable

Good Morning everyone,
I've been stumped with this error for a good days or two now.
My app is a small "Sample Request Log" for my textiles based company, it just needs to track samples and be able to edit/submit/delete them.
Whenever I try to update or create a new request I get a "undefined method `each' for "x":String" Where X is the option chosen in the drop down list (The drop down list is populated from another controller.)
Request_controller.rb:
class RequestsController < ApplicationController
before_action :set_request, only: [:show, :edit, :update, :destroy]
# GET /requests
# GET /requests.json
def index
if params[:tag]
#requests = Request.tagged_with(params[:tag])
else
#requests = Request.all
#requests = Request.order("request_date ASC")
end
end
# GET /requests/1
# GET /requests/1.json
def show
end
# GET /requests/new
def
new
#request = Request.new
#customers = Customer.all
#suppliers = Supplier.all
#designers = Designer.all
#statuses = Status.all
end
# GET /requests/1/edit
def edit
#customers = Customer.all
#suppliers = Supplier.all
#designers = Designer.all
#statuses = Status.all
end
# POST /requests
# POST /requests.json
def create
#request = Request.new(request_params)
#customers = Customer.all
#suppliers = Supplier.all
#designers = Designer.all
#statuses = Status.all
respond_to do |format|
if #request.save
format.html { redirect_to #request, notice: 'Request was successfully created.' }
format.json { render action: 'show', status: :created, location: #request }
else
format.html { render action: 'new' }
format.json { render json: #request.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /requests/1
# PATCH/PUT /requests/1.json
def update
#customers = Customer.all
#suppliers = Supplier.all
#designers = Designer.all
#statuses = Status.all
respond_to do |format|
if #request.update(request_params)
format.html { redirect_to #request, notice: 'Request was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #request.errors, status: :unprocessable_entity }
end
end
end
# DELETE /requests/1
# DELETE /requests/1.json
def destroy
#request.destroy
respond_to do |format|
format.html { redirect_to requests_url }
format.json { head :no_content }
end
end
def tagged
if params[:tags].present?
#requests = Request.tagged_with(params[:tags])
else
#requests = Request.postall
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_request
#request = Request.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def request_params
params.require(:request).permit(:request_date, :request_smd_number, :request_brief_description, :request_description, :request_supplier, :request_colours, :request_date_required, :request_required_for, :request_designer, :request_comments, :request_confirmed_comp_date, :request_received, :request_received_date, :request_date_sent, :request_tracking_number, :request_confirmed_comp_date, :request_confirmed_comp_date2, :request_confirmed_comp_date3, :request_confirmed_comp_date4, :request_confirmed_comp_date5, :request_confirmed_comp_date6, :tag_list, :tags, :supplier, :customer, :designer, :name)
end
end
Requests.rb
class Request < ActiveRecord::Base
validates_presence_of :request_smd_number, :request_date, :request_date_required,
:request_required_for, :request_brief_description, :request_comments, :tags,
:request_supplier
belongs_to :customer
belongs_to :designer
belongs_to :supplier
belongs_to :status
has_many :tags
accepts_nested_attributes_for :customer
accepts_nested_attributes_for :designer
accepts_nested_attributes_for :supplier
accepts_nested_attributes_for :status
acts_as_taggable_on :requests, :tags, :tag_list
end
The form I'm using can be found at https://github.com/jackybigz/samplelog/blob/master/app/views/requests/_form.html.erb (linking to git instead of pasting it in to keep the thread small.)
Whenever I take out the last line of the form '
<td class="span3"><%= collection_select :request, :tags, #statuses, :name, :name %></td>'
it works fine and updates the request so I've narrowed it down to that, but after shifting a bunch of relations and other things around, trying updates and different gem versions I've just come against a rock and a hard place.
I'm reasonably new to ruby and rails so any help and suggestions will be helpful, thanks.
P.S I've probably gone a completely different way with my apps code than I should of but it kind of works so it's how I did it.
EDIT here is the trace for the error.
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:333:in `replace'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:42:in `writer'
activerecord (4.0.0) lib/active_record/associations/builder/association.rb:78:in `tags='
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/persistence.rb:229:in `block in update'
activerecord (4.0.0) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/persistence.rb:228:in `update'
app/controllers/requests_controller.rb:67:in `block in update'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:363:in `call'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:363:in `retrieve_collector_from_mimes'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:189:in `respond_to'
app/controllers/requests_controller.rb:66:in `update'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__1386668850689043198__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) 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.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1572239184247043471__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) 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.0) 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.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process'
thin (1.5.1) lib/thin/connection.rb:79:in `catch'
thin (1.5.1) lib/thin/connection.rb:79:in `pre_process'
thin (1.5.1) lib/thin/connection.rb:54:in `process'
thin (1.5.1) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.5.1) lib/thin/backends/base.rb:63:in `start'
thin (1.5.1) lib/thin/server.rb:159:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
railties (4.0.0) lib/rails/commands.rb:73:in `tap'
railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
I found the answer this morning, came at with a fresh head and just kind of got it.
<td class="span3"><%= collection_select :request, :tags, #statuses, :name, :name %></td>
replaced :tags with :tag_list in the collection select and it works now.

state_machine gem integration with rails 4

I am facing a problem with usage of state_machine gem with my rails 4 app.
A have a model which include a column call state as described in the provided rails tutorial
http://gistflow.com/posts/679-state-machine-with-rails-basics
but when I define my state_machine as follows:
class Issue < ActiveRecord::Base
validates :title, :description, presence: true
has_many :notes
state_machine :initial => :new do
state :new, value: 0
state :analysed, value: 1
state :assigned, value: 2
state :inprogress, value: 3
state :inreview, value: 4
state :validation, value: 5
state :resolved, value: 6
state :cancelled, value: 7
state :closed, value: 8
state :rejected, value: 9
state :reopened, value: 10
end
def next
Issue.where("id > ?", self.id).first || Issue.first
end
def prev
Issue.where("id < ?", self.id).last || Issue.last
end
end
Here is my IssueConntroller
class IssuesController < ApplicationController
before_filter :find_issue, except: [:index, :new, :create]
def index
#issues = Issue.all
end
def new
#issue = Issue.new
end
def create
#issue = Issue.new(issue_params)
respond_to do |format|
if #issue.save
format.html {redirect_to #issue, :flash => { :success => "Issue succesfully created." } }
format.json {head :no_content}
else
format.html {render action: 'new'}
format.json { render json: #issue.errors, status: :unprocessable_entity }
end
end
end
def show
#note = Note.new
#note.issue_id = #issue.id
end
def edit
end
def update
respond_to do |format|
if #issue.update(issue_params)
format.html { redirect_to #issue, :flash => { :success => 'Issue was successfully updated.' }}
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #issue.errors, status: :unprocessable_entity }
end
end
end
def destroy
#issue.destroy
flash[:error]= "Issue '#{#issue.title}' Deleted!"
redirect_to issues_path
end
private
def issue_params
params.require(:issue).permit(:title, :description)
end
def find_issue
#issue = Issue.find(params[:id])
end
end
I am falling into a undefined method `state_machine' for # NoMethodError in IssuesController#index.
of course I have added gem 'state_machine line into my gemfile and run bundle install command.
It seems like the gem is not loaded by the rails application...
Thank you for helping me out with this problem ;)
here is the trace
activerecord (4.0.0) lib/active_record/dynamic_matchers.rb:22:in `method_missing'
app/models/issue.rb:5:in `<class:Issue>'
app/models/issue.rb:1:in `<top (required)>'
activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `load'
activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `block in load_file'
activesupport (4.0.0) lib/active_support/dependencies.rb:615:in `new_constants_in'
activesupport (4.0.0) lib/active_support/dependencies.rb:422:in `load_file'
activesupport (4.0.0) lib/active_support/dependencies.rb:323:in `require_or_load'
activesupport (4.0.0) lib/active_support/dependencies.rb:462:in `load_missing_constant'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
activesupport (4.0.0) lib/active_support/dependencies.rb:494:in `load_missing_constant'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
app/controllers/issues_controller.rb:6:in `index'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__901873103026712443__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655: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.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) 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.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__77618213725076532__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) li/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'b/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) 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'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
There is no problems in you code, try to reload SERVER after bundle , don't forget to add state:string or ìnteger since you use a value for state, to your model and of course same event
like
event :add_new do
transition new: :analysed
end
as a definition of state machine: is a transition form state to another
in rails c you can call some method for state machine
Issue.first.state_name
Issue.first.state_events
....
if you still have problem try to explain more :)

Simple rails association

I'm  new to RoR. I'm trying to create a basic web app where a Profile page shows a list of Items, which belongs to a specific profile.
So far I have:
rails generate scaffold Profile name:string
rails generate scaffold Item description:string
rake db:migrate
In the profile model: has_many :items In the item model: belongs_to :profile
When I try to create a new profile, I get the error:
undefined method `item' for #<Profile
Profile controller
class ProfilesController < ApplicationController
# GET /profiles
# GET /profiles.json
def index
#profiles = profile.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #profiles }
end
end
# GET /profiles/1
# GET /profiles/1.json
def show
#profile = profile.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: #profile }
end
end
# GET /profiles/new
# GET /profiles/new.json
def new
#profile = profile.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: #profile }
end
end
# GET /profiles/1/edit
def edit
#profile = profile.find(params[:id])
end
# POST /profiles
# POST /profiles.json
def create
#profile = profile.new(params[:profile])
respond_to do |format|
if #profile.save
format.html { redirect_to #profile, notice: 'profile was successfully created.' }
format.json { render json: #profile, status: :created, location: #profile }
else
format.html { render action: "new" }
format.json { render json: #profile.errors, status: :unprocessable_entity }
end
end
end
# PUT /profiles/1
# PUT /profiles/1.json
def update
#profile = profile.find(params[:id])
respond_to do |format|
if #profile.update_attributes(params[:profile])
format.html { redirect_to #profile, notice: 'profile was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #profile.errors, status: :unprocessable_entity }
end
end
end
# DELETE /profiles/1
# DELETE /profiles/1.json
def destroy
#profile = profile.find(params[:id])
#profile.destroy
respond_to do |format|
format.html { redirect_to profiles_url }
format.json { head :no_content }
end
end
end
Profile index.html.erb
<h1>Listing profiles</h1>
<table>
<tr>
<th>Name</th>
<th></th>
<th></th>
<th></th>
</tr>
<% #profiles.each do |profile| %>
<tr>
<td><%= profile.name %></td>
<td><%= link_to 'Show', profile %></td>
<td><%= link_to 'Edit', edit_profile_path(profile) %></td>
<td><%= link_to 'Destroy', profile, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New profile', new_profile_path %>
Profile _show.html.erb
<%= simple_form_for(#profile) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
</div>
<div class="form-inputs">
<%= f.input :item %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Full error trace:
activemodel (3.2.12) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.12) lib/active_record/attribute_methods.rb:149:in `method_missing'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1161:in `value_before_type_cast'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1149:in `value_before_type_cast'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1043:in `block in to_input_field_tag'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1043:in `fetch'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1043:in `to_input_field_tag'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:692:in `text_field'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1284:in `text_field'
simple_form (2.1.0) lib/simple_form/inputs/string_input.rb:13:in `input'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:29:in `block in render'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:27:in `each'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:27:in `render'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:29:in `block in render'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:27:in `each'
simple_form (2.1.0) lib/simple_form/wrappers/many.rb:27:in `render'
simple_form (2.1.0) lib/simple_form/wrappers/root.rb:15:in `render'
simple_form (2.1.0) lib/simple_form/form_builder.rb:117:in `input'
app/views/profiles/_form.html.erb:9:in `block in _app_views_profiles__form_html_erb___911765346923063960_2183588380'
actionpack (3.2.12) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.12) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
actionpack (3.2.12) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:607:in `fields_for'
actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:378:in `form_for'
simple_form (2.1.0) lib/simple_form/action_view_extensions/form_helper.rb:29:in `block in simple_form_for'
simple_form (2.1.0) lib/simple_form/action_view_extensions/form_helper.rb:48:in `with_simple_form_field_error_proc'
simple_form (2.1.0) lib/simple_form/action_view_extensions/form_helper.rb:28:in `simple_form_for'
app/views/profiles/_form.html.erb:1:in `_app_views_profiles__form_html_erb___911765346923063960_2183588380'
actionpack (3.2.12) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.12) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.12) lib/action_view/template.rb:143:in `render'
actionpack (3.2.12) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.12) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.12) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.12) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.12) lib/action_view/renderer/partial_renderer.rb:237:in `render'
actionpack (3.2.12) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.2.12) lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/profiles/new.html.erb:3:in `_app_views_profiles_new_html_erb___3444063506780261827_2182112400'
actionpack (3.2.12) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.12) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.12) lib/action_view/template.rb:143:in `render'
actionpack (3.2.12) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.12) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.12) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.12) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.12) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.12) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.12) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.12) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.12) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.12) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.12) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.12) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.12) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.12) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.12) lib/action_controller/metal/mime_responds.rb:196:in `respond_to'
app/controllers/profiles_controller.rb:29:in `new'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.12) lib/active_support/callbacks.rb:414:in `_run__312850119216024862__process_action__607287929354052739__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.12) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:601:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.12) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `_run__1382692569756144731__call__1219384665416315194__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.12) lib/rails/engine.rb:479:in `call'
railties (3.2.12) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.12) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
In order for the has_many :items to work you will need to have a profile_id:integer in your Item model.
You can accomplish by doing the following command
rails g migration add_profile_id_to_items profile_id:integer
rake db:migrate
That should create the foreign key needed for the association.
After that you should be able to do things like this
#profile = Profile.create name: "MyProfile"
#item = #profile.items.build description: "This is my awesome item"
#item.save
There are different ways to create items for a profile but that's the most straight forward way. Then to retrieve those items you would do something like this
#profile = Profile.find(some_id)
#items = Item.where(profile_id: #profile.id).all
or
#profile = Profile.find(some_id)
#items = #profile.items
First of all, your Profile object does not have 'item' field.
Check your object's attributes by executing these commands:
rails console
Profile.connection
Profile
or visit your db/schema.rb file
You will see that there is no attribute :item in your object's hash.
You probably want to show the profile's items in your show.html.erb view. First though, you need to create an Item of the profile that it belongs to like so:
item = Item.new(description: "Test description", profile_id: 1)
Then you can do:
Profile.first.items
Second, you have an error in your controller. Object's class should be capitalized, so:
rails console
profile = profile.new(name: "Test profile")
will raise an error
undefined method `new' for nil:NilClass

Resources