Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Create New Instance Of model

Repost ActiveRecord

  • Please log in to reply
2 replies to this topic

#1 vikhyat620

vikhyat620

    Passenger

  • Members
  • 9 posts

Posted 31 May 2014 - 03:45 PM

I want to add a repost button to the show action of my post model. The button should create a new post, where the content is defined as:

"#{current_user.fullname} shared #{@post.name}'s posts: #{@post.content}"

 

Is it possible to do this in a link_to tag?



#2 th3mus1cman

th3mus1cman

    Signalman

  • Members
  • 14 posts
  • LocationRichmond, VA

Posted 04 June 2014 - 05:35 PM

Need more details.  Can you provide user stories or something similar?


Rails Developer and Partner at Left + Right


#3 yujingz

yujingz

    Passenger

  • Members
  • 1 posts

Posted 14 August 2014 - 04:58 AM

Yeah you can. Something like this would work with no problems.

link_to "Repost", 'http://example.com/posts?' + {param1: 'value1', param2: 'value2'}.to_param, method: :post

However we generally don't recommend use link_to to do post operations. A button_to would be more suitable.







Also tagged with one or more of these keywords: Repost, ActiveRecord

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users