Domanda

I am a beginner with rails and would really appreciate some guidance!

Here is my Link_to in my first view:

<%= link_to micropost.user.name, micropost.user %> | <%= link_to "Send Message", new_conversation_path( target: micropost.user.name, reason: micropost.c1 ) %>

And here is my conversations controller:

  def new
    @target = params[:target]
    @reason = params[:reason]
  end

  def create
    recipient_names = conversation_params(:recipients).split(',')
    recipients = User.where(name: recipient_names).all
    conversation = current_user.
    send_message(recipients, *conversation_params(:body, :subject)).conversation
    redirect_to conversation
  end

As you can see, I'm using the mailboxer gem so I do not have a conversation model.

Finally, here is my form in the second view:

<%= simple_form_for :conversation, url: :conversations do |f| %>
  <%= f.input :recipients, @target %>
  <%= f.input :subject, @reason %>
  <%= f.input :body %>
  <div class="form-actions">
    <%= f.button :submit, class: 'btn-primary' %>
    <%= submit_tag 'Cancel', type: :reset, class: 'btn btn-danger' %>
  </div>

<% end %>

I want the conversation form to be automatically be preset with the recipient's name and micropost subject when the user clicks on the send message link.

Thank you in advance for your help!

È stato utile?

Soluzione

f.input :recipients, input_html: { value: @target }

f.input :subject, input_html: { value: @reason }

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top