Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialruby gupta
1,200 PointsPicture is not viewing in view full size
My picture uploader is uploaded the picture successfully, but when i try to view full size the picture is not coming '
My git repository is at: https://github.com/sarahgupta022/book.git
This is my show.html.erb
<p id="notice"><%= notice %></p>
<%= page_header do %>
<h1>Viewing Picture</h1>
<% end %>
<%= image_tag(picture.asset.url(:large), alt: @picture.caption, class: 'img-polaroid') %>
<h3><%= @picture.caption %></h3>
<p><%= @picture.description %></p>
<%= link_to 'Edit', edit_album_picture_path(@album, @picture) %> |
<%= link_to 'Album', album_pictures_path(@album) %>
Thanku You!
3 Answers
Raymond Sapida
33,049 PointsAfter cloning your repo and trying to edit the tests to get them passing, I found a few things you could edit.
For the album controller, I would edit the create and update actions to use album_params instead. It wasn't able to read it because of how params are passed to the controller.
@album = current_user.albums.new(album_params)
@album.update(album_params)
The same thing should be done for the pictures controller
@picture = @album.pictures.new(picture_params)
@picture.update(picture_params)
I would pass in the user_id
in the album controller test when you're using the create action and add this line to each one:
post :create, profile_name: @user.profile_name, album: { title: @album.title, user_id: @album.user_id }
I would also change the album fixture to point to the user instead of its id
vacation:
user: sarah
title: Vacation Pictures
and do the same for the pictures fixture
one:
album: vacation
user: sarah
caption: MyString
description: MyText
For the pictures controller tests, the problem seems to be coming from the image validations. I would edit the setup to include an image.
setup do
@picture = pictures(:one)
@asset = fixture_file_upload('example.png', 'image/png')
@album = albums(:vacation)
@user = users(:sarah)
@default_params = { profile_name: @user.profile_name, album_id: @album.id }
end
The image would have to be in the fixtures directory for this to work. Then add it to the create and update actions
post :create, @default_params.merge(picture: { caption: @picture.caption, description: @picture.description, asset: @asset })
patch :update, @default_params.merge(id: @picture, picture: { caption: @picture.caption, description: @picture.description, asset: @asset })
I'm not sure if this would fix the problem you originally had, but it should get rid of half of the failing tests and a few of the errors.
We'll see where it goes after that. Good luck!
Raymond Sapida
33,049 PointsHi there,
It looks like you need to add @
to one of the variables in your image tag. Specifically, this line:
<%= image_tag(picture.asset.url(:large), alt: @picture.caption, class: 'img-polaroid') %>
should be
<%= image_tag(@picture.asset.url(:large), alt: @picture.caption, class: 'img-polaroid') %>
I hope this was helpful and good luck!
ruby gupta
1,200 Pointsyes, that's remove my error but still picture is not showing...... i' don't now why picture is not coming. In my document.rb i'm able to view my attachment but its not working for picture.rb
Raymond Sapida
33,049 PointsIt could also be from your controller. I looked into your pictures_controller on GitHub and it's missing the asset field for pictures_params.
def picture_params
params.require(:picture).permit(:album_id, :user_id, :caption, :description)
end
should be:
def picture_params
params.require(:picture).permit(:album_id, :user_id, :caption, :description, :asset)
end
ruby gupta
1,200 PointsI updated picture_controller.rb with line
def picture_params
params.require(:picture).permit(:album_id, :user_id, :caption, :description, :asset)
end
but now it's giving new error again
ActionController::RoutingError (No route matches [GET] "/system/pictures/assets/000/000/023/small/IMG_20150226_212729712.jpg")
Why this happing agin....
in my web page it's show picture has been uploaded but picture is not displayed and when i check my rails server its giving me error "ActionController::RoutingError (No route matches [GET] ".
Raymond Sapida
33,049 PointsHmm, I'm not sure why you're getting that error because all the other parts of your code look correct. Could you check if the picture is being saved in the directory that it mentions? If it's there, you might need to add this line to config/environments/development.rb:
config.serve_static_assets = true
ruby gupta
1,200 PointsAfter getting this error i run rake test to find whats going on my app and i found 21 failures and 8 errors in my rails app. i think this may be causing problem.
$rake test
DL is deprecated, please use Fiddle
Run options: --seed 17389
# Running:
.E.........F............E.E......F.F.......E..E.............F...F.F...E...................E..........E........F.F.FF..F..FFFFFFFFFF...............
......
Finished in 11.321924s, 13.4253 runs/s, 19.6963 assertions/s.
1) Error:
StatusesControllerTest#test_should_destroy_status:
NoMethodError: undefined method `statuses' for nil:NilClass
app/controllers/statuses_controller.rb:92:in `destroy'
test/controllers/statuses_controller_test.rb:132:in `block (2 levels) in <class:StatusesControllerTest>'
test/controllers/statuses_controller_test.rb:131:in `block in <class:StatusesControllerTest>'
2) Failure:
StatusesControllerTest#test_should_update_status_for_the_current_user_when_logged_in [C:/Users/Arvind/project/book/test/controllers/statuses_contr
oller_test.rb:119]: Expected response to be a <error>, but was <302>
3) Error:
UserFriendshipsControllerTest#test_: #accept when logged in should update tha state to accepted. :
NameError: undefined local variable or method `do_put' for # <UserFriendshipsControllerTest:0x5107488>
test/controllers/user_friendships_controller_test.rb:283:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
4) Error:
UserFriendshipsControllerTest#test_: #accept when logged in should create activity. :
NameError: undefined local variable or method `do_put' for #<UserFriendshipsControllerTest:0x55f0ed8> test/controllers/user_friendships_controller_test.rb:294:in `block (4 levels) in <class:UserFriendshipsControllerTest>'
test/controllers/user_friendships_controller_test.rb:293:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
5) Failure:
UserFriendshipsControllerTest#test_: #index when logged in should display date information on an accepted friendship. [C:/Users/Arvind/project/bo
ok/test/controllers/user_friendships_controller_test.rb:43]:
<Friendship is accepted.> expected but was
<Friendship is accepted>..
Expected 0 to be >= 1.
6) Failure:
UserFriendshipsControllerTest#test_: #index when logged in pending friendships should not display pending or active friend's names. [C:/Users/Arv
ind/project/book/test/controllers/user_friendships_controller_test.rb:78]: Expected exactly 0 elements matching "div#friend-list", found 1.. Expected: 0 Actual: 1
7) Error:
UserFriendshipsControllerTest#test_: #accept when logged in should assign a user_friendship. :
NameError: undefined local variable or method `do_put' for #<UserFriendshipsControllerTest:0x56019f0>
test/controllers/user_friendships_controller_test.rb:277:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
8) Error:
UserFriendshipsControllerTest#test_: #accept when logged in should have a flash success message. :
NameError: undefined local variable or method `do_put' for #<UserFriendshipsControllerTest:0x6a85430>
test/controllers/user_friendships_controller_test.rb:288:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
9) Failure:
UserFriendshipsControllerTest#test_: #index when logged in accepted friendships should not display pending or active friend's names. [C:/Users/Ar
vind/project/book/test/controllers/user_friendships_controller_test.rb:118]:
Expected exactly 0 elements matching "div#friend-list", found 1..
Expected: 0
Actual: 1
10) Failure:
UserFriendshipsControllerTest#test_: #index when logged in requested friendships should not display pending or active friend's names. [C:/Users/A
rvind/project/book/test/controllers/user_friendships_controller_test.rb:97]:
Expected exactly 0 elements matching "div#friend-list", found 1..
Expected: 0
Actual: 1
11) Failure:
UserFriendshipsControllerTest#test_: #index when logged in should display pending information on a pending friendship. [C:/Users/Arvind/project/b
ook/test/controllers/user_friendships_controller_test.rb:37]:
<Friendship is pending.> expected but was
<Friendship is pending>..
Expected 0 to be >= 1.
12) Error:
ActivitiesControllerTest#test_should_get_index:
NoMethodError: undefined method `friends' for nil:NilClass
app/models/activity.rb:9:in `for_user'
app/controllers/activities_controller.rb:6:in `index'
test/controllers/activities_controller_test.rb:5:in `block in <class:ActivitiesControllerTest>'
13) Error:
UserTest#test_: #create_activity should increas the Activity count with an album. :
NoMethodError: undefined method `album' for #<UserTest:0x5878ff8>
test/models/user_test.rb:94:in `block (3 levels) in <class:UserTest>'
test/models/user_test.rb:93:in `block (2 levels) in <class:UserTest>'
14) Error:
UserTest#test_: #create_activity should set the targetable instance to the item passed in with an album. :
NoMethodError: undefined method `album' for #<UserTest:0x6f2ade0>
test/models/user_test.rb:99:in `block (2 levels) in <class:UserTest>'
15) Failure:
AlbumsControllerTest#test_should_create_activity_on_album_update [C:/Users/Arvind/project/book/test/controllers/albums_controller_test.rb:57]:
"Activity.count" didn't change by 1.
Expected: 3
Actual: 2
16) Failure:
AlbumsControllerTest#test_should_get_edit [C:/Users/Arvind/project/book/test/controllers/albums_controller_test.rb:46]:
Expected response to be a <success>, but was <404>
17) Failure:
AlbumsControllerTest#test_should_create_activity_on_album_delete [C:/Users/Arvind/project/book/test/controllers/albums_controller_test.rb:73]:
"Activity.count" didn't change by 1.
Expected: 3
Actual: 2
18) Failure:
AlbumsControllerTest#test_should_update_album [C:/Users/Arvind/project/book/test/controllers/albums_controller_test.rb:52]:
Expected response to be a <redirect>, but was <404>
19) Failure:
AlbumsControllerTest#test_should_destroy_album [C:/Users/Arvind/project/book/test/controllers/albums_controller_test.rb:64]:
"Album.count" didn't change by -1.
Expected: 0
Actual: 1
20) Failure:
PicturesControllerTest#test_should_create_activity_on_destroy [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:74]:
"Activity.count" didn't change by 1.
Expected: 3
Actual: 2
21) Failure:
PicturesControllerTest#test_should_show_picture [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:41]:
Expected response to be a <success>, but was <404>
22) Failure:
PicturesControllerTest#test_should_get_index [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:13]:
Expected response to be a <success>, but was <404>
23) Failure:
PicturesControllerTest#test_should_get_new [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:20]:
Expected response to be a <success>, but was <404>
24) Failure:
PicturesControllerTest#test_should_destroy_picture [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:65]:
"Picture.count" didn't change by -1.
Expected: 0
Actual: 1
25) Failure:
PicturesControllerTest#test_should_create_picture [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:25]:
"Picture.count" didn't change by 1.
Expected: 2
Actual: 1
26) Failure:
PicturesControllerTest#test_should_create_activity_on_create [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:34]:
"Activity.count" didn't change by 1.
Expected: 3
Actual: 2
27) Failure:
PicturesControllerTest#test_should_update_picture [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:53]:
Expected response to be a <redirect>, but was <404>
28) Failure:
PicturesControllerTest#test_should_get_edit [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:47]:
Expected response to be a <success>, but was <404>
29) Failure:
PicturesControllerTest#test_should_create_activity_on_update [C:/Users/Arvind/project/book/test/controllers/pictures_controller_test.rb:58]:
"Activity.count" didn't change by 1.
Expected: 3
Actual: 2
152 runs, 223 assertions, 21 failures, 8 errors, 0 skips
ruby gupta
1,200 PointsI can see each and every picture store in my rails app in public/system/picture/assets/000/021/original/Img_20150227_241046913.jpg. whatever picture i uploaded in my web page it is store there. All of them are store there and i can view it, but i can not view my images in my web page.
Raymond Sapida
33,049 PointsDo you get an error message when you're trying to view the image or does it show the picture for a broken link? I can't find anything wrong with the code and the only difference I could see between our implementation of it is how we validate the image and on the attachment validation
validates :asset, attachment_presence: true, on: :create
I'll try to write an integration test later tonight to duplicate the error that you're getting. Also, this link has what I did with the project and you might be able to find something that I overlooked. I've been comparing our code and nothing really jumps out to me.
ruby gupta
1,200 PointsNo i did't get any error or broken link in my web page. it's just upload and give picture link in my new picture page and when i try to view it comes with small broken image icon.
ActionController::RoutingError (No route matches [GET] "/system/pictures/assets/000/000/033/large/IMG_20150226_212729712.jpg") This error i receive in my rails server.
My Delete btn is also not working, when i try to delete picture it's return to view picture. I checked my picture.controller n picture.controller test too , but i found nothing. :(
Raymond Sapida
33,049 PointsTo me, it looks like the problem isn't with your controller or views. It might be the files aren't being served statically. You could add this line to config/environments/development.rb
config.serve_static_files = true
It might also be that the files are not being saved with the new styles. Do you have ImageMagick installed? If you do, try adding that directory to the command_path. For example, if you have the latest release installed in Program Files, the path could be:
Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.9.1-6-Q16-x64'
ruby gupta
1,200 PointsI updated app/model/picture.rb with this code:
has_attached_file :asset, :styles => {
:thumb => ['100x100#', :jpg, :quality => 70],
:preview => ['480x480#', :jpg, :quality => 70],
:large => ['800>', :jpg, :quality => 70],
:retina => ['1200>', :jpg, :quality => 30]
},
:convert_options => {
:thumb => '-set colorspace sRGB -strip',
:preview => '-set colorspace sRGB -strip',
:large => '-set colorspace sRGB -strip',
:retina => '-set colorspace sRGB -strip -sharpen 0x0.5'
}
And now picture is viewing in my web page. Thank You!!!!! So much!!!!!! :) but now i'm not able to upload avatar in my statuses page. I get error in my rails server : Unpermitted parameters: first_name, last_name, avatar.
ruby gupta
1,200 PointsHello again Now i'm trying to deploy my account with Heroku. When user make friendship between user and friends, we receive confimation mail. "friendship accpepted" and "you are now friend with username". In this stage i receive this error.
Net::SMTPAuthenticationError: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbv4V
This stage i am not able to find error. i change my config also.
This is my Production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'my appname.com',
user_name: 'sarahgupta022@gmail.com',
password: 'mypassword',
authentication: :plain,
enable_starttls_auto: true }
This is my development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply@example.com'}
config.action_mailer.delivery_method = :smtp
Raymond Sapida
33,049 PointsI think you're getting that error because Google doesn't recognize your app. This stack overflow link talks about how to let your app access gmail through their settings.
Also, I think you should set passwords and emails through an environment variable like this tutorial since you shouldn't commit that information into your repository.
ruby gupta
1,200 PointsYes!, Now it's working by changing the Settings of my gmail account. I have done- Settings > Forwarding and POP/IMAP and enable the protocols(s).
Raymond Sapida
33,049 PointsThat's great to hear!
ruby gupta
1,200 PointsThanks!!!! :)
ruby gupta
1,200 Pointsruby gupta
1,200 PointsIn album all errors remove but in picture i have still one problem remaining is "@asset = fixture_file_upload('example.png', 'image/png')". i put as: @asset = fixture_file_upload('rails.png', 'image/png') rails.png is in my rails app/assets/images/rails.png
I also try to put asset in my fixtures like asset: rails.png but still it not working
Raymond Sapida
33,049 PointsRaymond Sapida
33,049 PointsThe file should be at the fixtures folder like it says on the error message
C:/Users/Arvind/project/book/test/fixtures/rails.png
but if that still doesn't work, you could also try:
@asset = fixture_file_upload(Rails.root.join('/test/fixtures/rails.png'), 'image/png')
@asset = Rack::Test::UploadedFile.new(Rails.root.join('test/fixtures/rails.png'), 'image/png')
or
@asset = File.new(Rails.root.join('test/fixtures/rails.png'), 'image/png')
Testing uploaded files can be tricky especially depending on which Rails version or testing framework you use, but these are the three things that have worked for me in the past.
ruby gupta
1,200 Pointsruby gupta
1,200 PointsThank you . now no more error in my album n picture but problem is same picture is being uploaded but not viewing. :( I don't know why my rails app not working.even there is no error. In my rails app i can post new status with attachment and i can view my picture as well as, i can zoom in - zoom out my picture. but in my album this is not working why? what i'm missing. why this happening in same app.
Raymond Sapida
33,049 PointsRaymond Sapida
33,049 PointsAre the pictures being saved somewhere in the
public/systems/
directory ? I think the problem might be that the picture is not being saved in the correct directory or that it's not being saved at all.ruby gupta
1,200 Pointsruby gupta
1,200 PointsI updated app/model/picture.rb with this code:
And now picture is viewing in my web page. Thank You!!!!! So much!!!!!! :) but now i'm not able to upload avatar in my statuses page. I get error in my rails server : Unpermitted parameters: first_name, last_name, avatar.
Raymond Sapida
33,049 PointsRaymond Sapida
33,049 PointsThat's great! I'm glad that you're able to view your pictures now!
With regards to the avatar, you could add the
:avatar
field to the#configure_permitted_parameters
method like this:Right now, the permitted parameters you have for your app only works during registration and not when you update your settings. Are you adding the avatar image through that?
If you're setting the avatar when the user registers their account, you can add it to the method you currently have like this:
ruby gupta
1,200 Pointsruby gupta
1,200 Pointsyes it's working great!!!!! Thank You!!!!! so much!!!! :) I am so happy, This was my first project in ruby on rails and i completed perfectly. I never thought this paperclip is going to leave me easily. But with the help of u i completed my work. And I heartily Thanks to "team tree house" for wonderful project. Now, I'm ready to start my new Project with treehouse in ruby on rails.
Raymond Sapida
33,049 PointsRaymond Sapida
33,049 PointsThat's great! You're welcome and if you have any more problems along the courses, feel free to ask in the forums anytime =]