Saving information in bank and sending via post in Rails

1

I have a view that explains a system and allows the user to submit content for publication. He just types in a textarea and this text is sent to a WP blog, along with his username and email, which turns him 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 record will have the user name, your email, and the article title (picking up the substring between the h1 tags).

I made the scaffold to generate the manipulation of the articles, but I can not do this part of capturing the title, because there is no $ _POST like in PHP. I searched 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>
    
asked by anonymous 09.09.2015 / 03:23

1 answer

0

Eduardo, in his controller take a look at the variable params, it is responsible for transporting information from the form to your controller.

In your controller use the Model to save these.

To save this same post in 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);

Ideally you should create a Lib with this connection and pass the SQL to run. I did not test the code, but the idea is that!

    
18.09.2015 / 16:37