Rails 5 with the error statement Isa directory@rb_sysopen

Asked 2 years ago, Updated 2 years ago, 100 views

I am creating an app while looking at the Progate rails course.I'm stuttering to upload my profile picture.I brought the code exactly as it is from the Progate, but it doesn't work.
I've never seen an error statement before, so I don't understand it well even if I look it up.It has stopped here for more than half a day.
What I want to do is

Save image to public/user_images
Display the saved image on the profile page (you can change the image for each user)
That's it.

Please let me know.

home_controller.rb

def update_user
     @user=User.find_by (id:params[:id])
     @uu ser.name=params[:name]
     @user.email=params[:email]
     if params [:image]
       @user.image_name="#{@user.id}.jpg"
       image=params[:image]
       File.binwrite("public/user_images/#{@user.image_name}", image.read)
     end
     [email protected]
       flash[:notice] = "User information edited"
       redirect_to("/")
     end
  end

  def profile
     @user=User.find_by (id:params[:id])
     @post=Post.find_by (id:params[:id])
     @likes=Like.where(user_id:@uu-ser.id)
  end

routes.rb

Rails.application.routes.drawdo
get "home/test" = > "home#barbajs"


  get":id/edit_profile"=>"home#edit_profile"
  get "account /:id/edit" = > "home#edit_account"
  post "user/:id/update" = > "home#update_user"
  get 'pay/payment'
  device_for —users
  get "home/:id/likes" = > "home#likes"
  post "like/:post_id/create" =>"like#create"
  post "like/:post_id/destroy" =>"like#destroy"

  root'home#index'
  get "home/new_fc" = > "home#new_fc"
  post "home/create" = > "home#create"
  get "home/profile/:id" = > "home#profile"
  get":id/show_fc"=>"home#show_fc"
  get":id/edit_fc"=>"home#edit_fc"
  post":id/update_fc"=>"home#update_fc"
  post": id/fc/destroy"=>"home#destroy"
  get":id/setting"=>"home#setting"
  get "pay" = > "pay#payment"
  get "home/new_fc_content" = > "home#new_fc_content"
  post "home/content_create" = > "home#content_create"
end

edit_profile.html.erb (Edit Profile Page)

<h3>Edit Profile</h3>

<%=form_tag("/user/#{current_user.id}/update", {multipart:true})do%>
  <p>Username</p>
  <textarea name="name" class="textbox">%=current_user.name%></textarea>
  <li>Change self-introduction</li>
  <li>Change profile picture</li>
  <p>Image </p>
  <input name="image" type="file">
  <input type="submit" value="Now you're done!" class="btn btn-light-green btn-size-large">
<%end%>

profile.html.erb (profile page)

<div class="main">
<h2><%=@u ser.name%>/h2>
<img src="<%="/user_images/#{@user.image_name}"%>">
<table>
  <tr>
    <th>Fan Club General Members</th>
    <th>Number of fan clubs joined</th>
  </tr>
  <tr>
    <td>11</td>
    <td>20</td>
  </tr>
</table>

error statement

ruby-on-rails ruby image

2022-09-30 19:26

1 Answers

Is a directory error stating that you tried to open a file, but it was a directory.

The direct cause is that the filename you tried to open is public/user_images/, as shown in the screenshot.
In other words,

File.binwrite("public/user_images/#{@user.image_name}", image.read)

In this part, I think @user.image_name is " or nil.

I don't know more about the User class code because it's not in the questionnaire
If the user class image_name or image_name= methods are self-created methods, why don't you double-check these codes?


2022-09-30 19:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.