Grabbing the right article ID to merge articles with in Publify

887 Views Asked by At

I'm implementing a feature that allows Publify to merge two articles. On the admin page I created the following form (I'm not sure this is correct for what I'm after), which ultimately should allow one to input another article's ID and merge it with the current article being viewed (comments should be preserved but should only have one author).

This form should only be viewable by admins, but I haven't implemented this logic yet.

<%= form_tag({:controller => "admin/content", :action => "merge"}, :method => "put", :class => 'article') do %>
  <%= label_tag(:merge_with, "Article ID") %>
  <%= text_field_tag(:merge_with) %>
  <%= submit_tag("Merge") %>
<% end %>

I also created the following method in admin/content_controller.rb

def merge
  @current_article = Article.find(params[:id])
  #(this variable should grab the article ID from the form) @input_article =
  @merged_article = @current_article + @input_article
  return @merged_article  
end

The problem with this is I'm not sure how to grab the article ID that was inputed from the form and utilize it in my controller.

2

There are 2 best solutions below

2
On BEST ANSWER

It should be in your params hash, at params[:merge_with]

Whatever field you want to access from a form you submitted, it's going to show up in your params hash with the key value being the id of that input field on the form.

Edit:

Based on the code you have there, your params[:id] value is also going to be nil when you call your controller's merge method, because your URI will just be 'admin/content/merge' when it actually needs to be 'admin/content/merge/:id'.

0
On

Since the merge articles form is on the edit article page then the URI should already contain the id of the current article being edited.

So you can just get it from params hash like this params[:id]