How to store the information entered in textarea in a variable in the method

This time, I will introduce how to store the information entered in textarea in a variable in the method.

ruby:new.html.erb



<div class="infomation_new">
 <%= form_tag("/infomations",method: :post) do |f|%>
  <p class = "infomation_new_textarea"><%= text_field_tag :talent_name%></p></br>
  <p class = "infomation_new_submit"><%= submit_tag 'Search'%></p>
 <% end %>
</div>

The focus this time is on: talent_name next to text_field_tag. Make this description

infomations_controller.rb


def create
        talent_name = params[:talent_name]
        agent = Mechanize.new
        personal_page = agent.get('https://talent-dictionary.com/' + talent_name)
        aaas = personal_page.at('.talent_name_wrapper')
        @ages = aaas.at('.age').inner_text.delete('age').to_i if aaas.at('.age')
        @names = aaas.at('h1').inner_text  if aaas.at('h1')
        @image_urls = personal_page.at('.main_image img').get_attribute('src') if personal_page.at('.main_image img')
        @infomation = Infomation.where(name: @names).first_or_initialize
        @infomation.age = @ages
        @infomation.image_url = @image_urls
        @infomation.save
end

You can store it in a variable in the method by setting talent_name = params [: talent_name] on the second line. For example, if you enter Taro Yamada

[16, 25] in /home/ec2-user/environment/filebook/app/controllers/infomations_controller.rb
   16:         @ages = aaas.at('.age').inner_text.delete('age').to_i if aaas.at('.age')
   17:         @names = aaas.at('h1').inner_text  if aaas.at('h1')
   18:         @image_urls = personal_page.at('.main_image img').get_attribute('src') if personal_page.at('.main_image img')
   19:         @infomation = Infomation.where(name: @names).first_or_initialize
   20:         @infomation.age = @ages
   21:         @infomation.image_url = @image_urls
   22:         @infomation.save
   23:         byebug
=> 24:     end
   25: end
(byebug) talen_name
*** NameError Exception: undefined local variable or method `talen_name' for #<InfomationsController:0x00007f0fb5777ce0>
Did you mean?  talent_name

nil
(byebug) talent_name
"Yamada Taro"
(byebug) 

That's it.

Recommended Posts

How to store the information entered in textarea in a variable in the method
How to change the value of a variable at a breakpoint in intelliJ
How to display the text entered in text_area in Rails with line breaks
How to reference a column when overriding the column name method in ActiveRecord
How to store Rakuten API data in a table
How to mock a super method call in PowerMock
How to create a method
How to get the class name / method name running in Java
How to create a placeholder part to use in the IN clause
How to store a string from ArrayList to String in Java (Personal)
Create a method to return the tax rate in Java
How to add the same Indexes in a nested array
[Rails] How to display information stored in the database in view
How to use the link_to method
How to use the include? method
How to use the form_with method
How to insert a video in Rails
[Rails] How to use the map method
[Java] How to use the toString () method
How to have params in link_to method
[Java] How to search for a value in an array (or list) with the contains method
Notation to put a variable in a string
How to get the date in java
How to publish a library in jCenter
How to test a private method in Java and partially mock that method
How to get the current date as a string in yyyyMMdd format
[Rails] How to get the user information currently logged in with devise
How to get the absolute path of a directory running in Java
[Ruby] Returns characters in a pyramid shape according to the entered numbers
How to check the logs in the Docker container
How to display a web page in Java
How to add sound in the app (swift)
How to create a class that inherits class information
How to run a djUnit task in Ant
Output of how to use the slice method
How to add a classpath in Spring Boot
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to make a follow function in Rails
How to build the simplest blockchain in Ruby
How to check Rails commands in the terminal
[Ruby basics] How to use the slice method
How to automatically generate a constructor in Eclipse
How to get the ID of a user authenticated with Firebase in Swift
How to check if an instance variable is defined in a Ruby class
How to make a judgment method to search for an arbitrary character in an array
How to store data simultaneously in a model associated with a nested form (Rails 6.0.0)
[Rails] How to operate the helper method used in the main application with Administrate
How to make a unique combination of data in the rails intermediate table
How to clear all data in a particular table
How to create a Java environment in just 3 seconds
How to set the display time to Japan time in Rails
[Java] How to omit the private constructor in Lombok
How to implement a like feature in Ajax in Rails
[Java] Integer information of characters in a text file acquired by the read () method
How to get information about associated tables in many-to-many tables
How to create a Spring Boot project in IntelliJ
How to create a data URI (base64) in Java
Organized how to interact with the JDK in stages
How to save a file with the specified extension under the directory specified in Java to the list
How to launch another command in a Ruby program