I am making a system that allows you to post images with Ruby on rails.
I want to display an image in the background.
Images posted in active storage can now be saved and displayed.
After that, when I posted to S3 on AWS and tried to save and display the image, an error occurred and
Corrected the HTML description.
I can see that the image data is sent to the record normally,
I am in trouble because the image is not displayed.
I think there is a problem with the code that displays the image in _item.html.erb.
app/veiws/veiws/_item.html.erb<code>➡︎ Image is not displayed with this code ➡︎ This code causes an error<% # <span><% = image_tag'arrow_top.png'%></span> <ul> <li> <% = link_to'Details', item_path (item.id), method:: get%> </li> <% if user_signed_in?&¤t_user.id == item.user_id%> <li> <% = link_to'Delete', item_path (item.id), method :: delete%> </li> <% # Prefix argument%> <% # Item ID (item.id)%> <% # HTTP method is an HTTP method called DELETE%> <% # method option with symbol: delete%> <li> <% = link_to'edit', edit_item_path (item.id), method:: get%> <% # get Returns information from the server to the browser. It is used to obtain information, such as when simply browsing a website. %> <% # Check path with Prefix%> </li> <% end%></ul> <p><% = item.text%></p> <span> "> <span>Posted by</span><% = item.user.nickname%> </span> >
➡︎ Error details
NoMethodError in Users # show
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line # 1 raised:
undefined method `url'for # Extracted source (around line # 1):What I tried
<pre><code>app/veiws/veiws/_item.html.erb<code>Contents of the code () after the above correction No image displayed, no error➡︎ When using the first pattern image_url
Sprockets :: Rails :: Helper :: AssetNotFound in Items # index
Showing /Users/uraokayuutarou/projects/nostalgia/app/views/items/_item.html.erb where line # 1 raised:
The asset "" is not present in the asset pipeline.
Extracted source (around line # 1):<% #<% # );"><% # );"><% # ');"><% # An error occurred in the above code.
Error screenshot
https://gyazo.com/f1fe843012299d2dc4ec19060bf82905
Continued
https://gyazo.com/e89d008392120fa0a804ff47f8a90bf3
Supplement
S3 creates a bucket and edits the bucket policy,
I bundle installed gem "aws-sdk-s3", require: false on Gemfie.
Then change config.active_storage.service =: amazon from local to config/environments/delopment.rb.
Next, uncheck "Block all public access".
Checked New Public Bucket Policy, Any Bucket Policy.
Added to config/storage.yml
amazon:
service: S3
access_key_id:<% = ENV ['AWS_ACCESS_KEY_ID']%>secret_access_key:<% = ENV ['AWS_SECRET_ACCESS_KEY']%>region: ap-northeast-1
bucket: own bucket name
Environmental setting
config/environment/developments.rb
Last description
# default_url_options [: host] = "localhost: 3000"
host ='samplehost'
Rails.application.routes.default_url_options [: host] = host
# Probably defined in production environment
I was able to describe here and display it locally.
Using the url_for method
Postscript 11/6 20:42
1) I confirmed that I was able to save to S3 with the AWS S3 object on the WEB page.
2) Contents of item_params =>"Pants", "image" =># , @original_filename = "Screenshot 2020-11-06 19.46.55.png", @content_type = "image/png", @ headers = "Content-Disposition: form-data;name = \ "item [image] \";filename = \ "\ xE3 \ x82 \ xB9 \ xE3 \ x82 \ xAF \ xE3 \ x83 \ xAA \ xE3 \ x83 \ xBC \ xE3 \ x83 \ xB3 \ xE3 \ x82 \ xB7 \ xE3 \ x83 \ xA7 \ xE3 \ x83 \ x83 \ xE3 \ x83 \ x88 2020-11-06 19.46.55.png \ "\ r \ nContent-Type: image/png \ r \ n" >, "user_id" =>1} permitted: true>
3) Definition of item model
params.require (: item) .permit (: text,: image) .merge (user_id: current_user.id
-
Answer # 1
Related articles
- ruby on rails - [rails beginner] i want to display the posted content on my page
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- ruby on rails - the image cannot be saved in s3 and cannot be displayed in the view aws :: sigv4 :: errors :: missingcredentials
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails - [rails] the initial image of the icon for the user is not displayed
- ruby on rails - i want to display search results
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby on rails - i want to display all the images in the [rails] directory in the browser!
- ruby on rails 6 - [rails] i want to update the display of chat room participants etc in real time
- ruby on rails - about image posting page argumenterror
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby on rails - about image distribution on heroku and s3
- ruby on rails 6 - i want to change the display of the product detail page according to the user's conditions
- ruby on rails - [rails] how to round (omission and display) the character string of link_to
- ruby on rails - i want to display the numbers entered in the line graph of chart kick
- ruby on rails - creating an image posting application where the data entered in the form is not saved
- ruby - i want to display specific columns in rails in descending order of numbers
- ruby on rails 6 - i want the posted prototype to be displayed on the top page
- ruby - rails comment function display
- ruby on rails - about image distribution on heroku and s3
- ruby on rails - s3 images are not saved on the ec2 server
- html - data cannot be acquired or displayed with parameters
- ruby - i want to save to tave from a site made with rails
- ruby - validation error when saving intermediate table
- ruby - unable to save comments in db (rails)
- ruby - data is not updated by update action rails
- ruby on rails - [rails] i want to solve "no route matches [post]"/messages/search "" of "routing error&
- ruby - allow rails chat app to save to only one room
);">
Here, I wonder if it's not image_tag but image_url or image_path.