Form_for @object with carrierwave upload form

This form raises undefined method `pictures_path’ for
#<#Class:0xaea3ad0:0xbb9cb4c>

<%= form_for(@picture, :html => { :multipart => true }) do |f| %>

<%= f.file_field :image %>

<%= f.submit %>

<% end %>

Hello,

can you show your model and controller file ?

W dniu 22.01.2016 o 05:16, fugee ohu pisze:

On Thursday, January 21, 2016 at 11:40:30 PM UTC-5, Przemek Kosakowski
wrote:

Hello,

can you show your model and controller file ?

class PicturesController < ApplicationController
def index
@pictures = Picture.all
end

def new
@picture = current_user.profile.pictures.new
end

def create
@picture = Picture.new(picture_params)

if @picture.save
  redirect_to current_user_profile_pictures_path, notice: "The 

picture
#{@picture.name} has been uploaded."
else
render “new”
end
end

def destroy
@picture = Picture.find(params[:id])
@picture.destroy
redirect_to current_user_profile_pictures_path, notice: “The
picture
#{@picture.name} has been deleted.”
end

class Picture < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
mount_uploader :imageable, PictureUploader
validates :name, presence: true
end

private
def picture_params
params.require(:picture).permit(:name, :attachment)
end
end

I see you trying upload some picture, please use this gem [1]. You be
able in easy way customize your picture uploader.

[1]: paperclip https://github.com/thoughtbot/paperclip

Have you relation between user -> profile -> picture ?

W dniu 22.01.2016 o 10:40, fugee ohu pisze:

On 22 January 2016 at 04:16, fugee ohu [email protected] wrote:

This form raises undefined method `pictures_path’ for
#<#Class:0xaea3ad0:0xbb9cb4c>

<%= form_for(@picture, :html => { :multipart => true }) do |f| %>

Have you defined that route in routes.rb (via resources: pictures for
example)?

I agree with Przemek that you would probably be better off using
paperclip for uploading. It makes life very easy.

Colin

On Friday, January 22, 2016 at 5:16:55 AM UTC-5, Colin L. wrote:

I agree with Przemek that you would probably be better off using
paperclip for uploading. It makes life very easy.

Colin

I wouldn’t disagree Here’s the route: post
‘users/:id/profiles/:id/pictures/new’ => ‘pictures#new’

Look on below situation:

class User < ActiveRecord::Base
has_one :profile, :autosave => true
end

class Profile < ActiveRecord::Base
belongs_to :user
has_attached_file :picture,
:styles => { medium: “300x200>”, thumb: “100x100>”
},
:storage => :s3,
:s3_credentials => Proc.new{|a|
a.instance.s3_credentials}
validates_attachment_content_type :picture, content_type:
/\Aimage/.*\Z/
end

this two class + paperclip and that’s enough. I think You don’t need
extra model for keeping user profile picture, you can easily add column
“picture” in Your Profile model.

W dniu 22.01.2016 o 11:20, fugee ohu pisze:

Hi,

On Fri, Jan 22, 2016, at 19:20, fugee ohu wrote:

example)?

I agree with Przemek that you would probably be better off using
paperclip for uploading. It makes life very easy.

Colin

I wouldn’t disagree Here’s the route: post
‘users/:id/profiles/:id/pictures/new’ => ‘pictures#new’

That route doesn’t add the pictures_path named route. Try adding as: 'pictures' option.

Also note that neither the action name nor route you specified follows
rails standard convention[1].

[1] http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

OK But now, the subject is carrierwave Users has_one profile; Profile
has_many pictures as :imageable I’m totally lost, I dunno what role in
the
upload the controller’s supposed to play since i have the uploader.rb

On Thursday, January 21, 2016 at 11:16:40 PM UTC-5, fugee ohu wrote:

<%= f.submit %>

<% end %>

thanks, add column picture to the profile model? profiles can have
many
pictures

many pictures you mean “a few different user profile photo” or you mean
“few copy of the same picture but different size/dimension” ?

W dniu 22.01.2016 o 11:59, fugee ohu pisze:

On Friday, January 22, 2016 at 6:01:33 AM UTC-5, Przemek Kosakowski
wrote:

To view this discussion on the web visit

https://groups.google.com/d/msgid/rubyonrails-talk/5b59e848-b53e-453a-a68f-9a5d335dce49%40googlegroups.com?utm_medium=email&utm_source=footer

https://groups.google.com/d/msgid/rubyonrails-talk/5b59e848-b53e-453a-a68f-9a5d335dce49%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout.

Many pictures, not just different versions of the same picture

On 22 January 2016 at 10:20, fugee ohu [email protected] wrote:

I agree with Przemek that you would probably be better off using
paperclip for uploading. It makes life very easy.

Colin

I wouldn’t disagree Here’s the route: post
‘users/:id/profiles/:id/pictures/new’ => ‘pictures#new’

#new is the method used for showing the form, and is a get not a post,
form_for needs the route for posting to the create method. If you
don’t supply a url in the call of form_for it assumes pictures_path
which must have been provided using resources: pictures for at least
the create method. See [1] for details. I expect that is described
in the Rails Guides also.

[1] http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for

Colin

Many pictures for user profile ? I can’t agree but okay. If you have
many pictures for one user then you should create Gallery model instead
of Picture. Even on fb user be able to have only one profile picture.

But I don’t judge, maybe your solution is effective.

W dniu 22.01.2016 o 12:06, fugee ohu pisze:

On Friday, January 22, 2016 at 6:11:34 AM UTC-5, Przemek Kosakowski
wrote:

On Friday, January 22, 2016 at 6:01:33 AM UTC-5, Przemek Kosakowski wrote:

https://groups.google.com/d/msgid/rubyonrails-talk/5b59e848-b53e-453a-a68f-9a5d335dce49%40googlegroups.com

To unsubscribe from this group and stop receiving emails from it, send an

Yes, I’m using bootstrap-image-gallery (an extension of bluimp) Where
would
I see the table definition for Gallery model?

On Thursday, January 21, 2016 at 11:16:40 PM UTC-5, fugee ohu wrote:

<%= f.submit %>

<% end %>

And how does the file actually get uploaded? I have to add code to my
controller to upload the file? If yes, what do i need the uploader for?

On Thursday, January 21, 2016 at 11:16:40 PM UTC-5, fugee ohu wrote:

<%= f.submit %>

<% end %>

the docs for paperclip describe as being used for attachments, in my
case
i’m just uploading files not as attachments

<%= f.file_field :image %>

<%= f.submit %>

<% end %>

the docs for paperclip describe as being used for attachments, in my case i’m
just uploading files not as attachments

When they refer to attachments in Paperclip, what they mean is that you
are attaching a file to a Rails model instance. The model instance is
saved in the database, and the file in the filesystem, so it is an
attachment if you look at it the way they mean you to.

Walter

On Friday, January 22, 2016 at 5:15:10 PM UTC-5, Walter Lee D. wrote:

On Thursday, January 21, 2016 at 11:16:40 PM UTC-5, fugee ohu wrote:

<%= f.submit %>

<% end %>

And how is the file supposed to actually get uploaded, i changed the
create
action in my pictures controller to look like this but the file didn’t
get
uploaded

def create
@picture = Picture.new(picture_params)
if @picture.save
uploader = PictureUploader.new
picture = params[:imageable]
uploader.store!(picture)
redirect_to user_profile_path(current_user.id,
current_user.profile.id), notice: “The picture #{@picture.name} has been
uploaded.”
else
render “new”
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs