Saving information in bank and sending via post in Rails

Asked

Viewed 186 times

1

I have a view that explains a system and allows the user to send content for publication. It just type in a textarea and this text is sent to a WP blog, along with your username and email, which turns it into a guest post.

The problem is that now I need to make a modification so that, in addition to sending the data to WP, the system saves them in the Mysql database associated with Rails. The registration will have the user’s name, e-mail address and article title (taking the substring between the H1 tags).

I scaffolded to generate article manipulation, but I can’t do this part of the title capture, because there is no $_POST like in PHP. I looked everywhere and could not find a satisfactory solution. How can I make the information to be saved in the bank and then sent to the WP blog?

Current code snippet:

<%= hidden_field_tag :nome_autor, @current_user.name %>
<%= hidden_field_tag :email_autor, @current_user.email %>
<textarea name = "texto"><h1>SEU TÍTULO AQUI</h1><br>Escreva seu artigo aqui e nos envie!</textarea>
<button type = "submit">Enviar Artigo</button>

1 answer

0


Eduardo, in your controller take a look at the params variable, she is responsible for carrying the form information to your controller.

In your controller use Model to save these.

To save this same post to WP, I’ve never done this, but you can create an extra connection in Rails

  @connection = ActiveRecord::Base.establish_connection(
              :adapter => "mysql2",
              :host => "localhost",
              :database => "wp_banco_de_dados",
              :username => "root",
              :password => "root123"
  )

  sql =  "INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`,   `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (value1,value2,value3,...)";


  @result = @connection.connection.execute(sql);

Ideal is you create a Lib with this connection and pass the SQL to be executed. I didn’t test the code, but that’s the idea!

  • But how can I send to the WP page after?

  • @Eduardo edited the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.