ruby on rails - How to submit a form and delete a post -
i have 2 models in rails project: link
, campaign
. in show.html.erb link
have form create new campaign
looks this
<%= form_for :campaign, url: campaigns_path |f| %> <%= f.hidden_field :name, value: current_user.email %> <%= f.hidden_field :product, value: @link.product %> <%= f.hidden_field :title, value: @link.title %> <%= f.hidden_field :website, value: current_user.website %> <%= f.hidden_field :productlink, value: @link.url %> <%= f.hidden_field :description, value: @link.description %> <%= f.hidden_field :date, value: date.today.to_s %> <br> <br> <%= f.submit :"let's go make money", class: "btn btn-primary" %> <% end %>
this works. problem deleting post link
while creating new post based on campaign
. basically, want submit form , delete else.
you pass id of link want destroy in form_for:
<%= form_for @campaign, :url => { :controller => :campaign, :action=>:create, :link_id => @link.id } |f| %> <%= f.hidden_field :name, value: current_user.email %> <%= f.hidden_field :product, value: @link.product %> <%= f.hidden_field :title, value: @link.title %> <%= f.hidden_field :website, value: current_user.website %> <%= f.hidden_field :productlink, value: @link.url %> <%= f.hidden_field :description, value: @link.description %> <%= f.hidden_field :date, value: date.today.to_s %> <br> <br> <%= f.submit :"let's go make money", class: "btn btn-primary" %> <% end %>
in links_controller.rb:
def show @campaign = campaign.new end
and in campaigns_controller.rb: def show @ end
def create @link = link.find(params[:link_id]) @link.destroy ... # create campaign end