Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. ActiveRecord::RecordNotFound in AlbumsController#create
  2.  
  3. Couldn't find User without an ID
  4.  
  5. <%= form_for (@album), :remote => true, :html => { :id => "uploadform", :multipart => true } do |f| %>
  6. <div>
  7. <%= f.label :name %>
  8. <%= f.text_field :name %>
  9.  
  10.  
  11. <%= f.label :description %>
  12. <%= f.text_area :description %>
  13.  
  14.  
  15. <%= f.fields_for :avatar do |avatar_form| %>
  16. <%= avatar_form.label :avatar, "Upload" %>
  17. <%= avatar_form.file_field :avatar, :multiple => true %>
  18. <% end %>
  19.  
  20.  
  21. <%=f.submit %>
  22. </div>
  23. <% end %>
  24.  
  25. def create
  26. @users = User.all
  27. @user = User.find(params[:user_id])
  28. @album = @user.albums.build(params[:album])
  29. if @album.save
  30. flash[:success] = "Album created!"
  31. end
  32. end
  33.  
  34. Pholder::Application.routes.draw do
  35. resources :users do
  36. resources :albums
  37. end
  38.  
  39. resources :albums do
  40. resources :pictures
  41. end
  42.  
  43. class Album < ActiveRecord::Base
  44. attr_accessible :avatar, :name, :description
  45. has_and_belongs_to_many :users
  46.  
  47. has_attached_file :avatar
  48. end
  49.  
  50. def create
  51. @users = User.all
  52. @album = Album.new(params[:album].merge!(:user_id => current_user))
  53. if @album.save
  54. flash[:success] = "Album created!"
  55. end
  56. end
  57.  
  58. def create
  59. @users = User.all
  60. @album = Album.new(params[:album])
  61. @album.user_id = current_user.id
  62. if @album.save
  63. flash[:success] = "Album created!"
  64. end
  65. end
Add Comment
Please, Sign In to add comment