ruby on rails - How to pass parameters through link_to and have them as preset values in a form_for? -


i beginner rails , appreciate guidance!

here link_to in 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 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 can see, i'm using mailboxer gem not have conversation model.

finally, here form in second view:

<%= simple_form_for :conversation, url: :conversations |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 conversation form automatically preset recipient's name , micropost subject when user clicks on send message link.

thank in advance help!

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

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


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -