PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] How to use form partial for custom create method?

 May 18, 2022     clone, forms, partial, routes, ruby-on-rails     No comments   

Issue

I have a trouble with creating custom create method.
I'm using Projects model and projects controller. After new project is added it redirects to that projects show page. Here comes the problem. I have a button to call clone_project method since I need to create new project with the data from selected project and with empty name field. So, I've created route:

resources :projects do
  get 'clone/:id', action: 'clone_project', on: :collection
end

and a view page that uses form partial. With this I've manage just to edit existing project since I don't seem to get how to use form with post method like in create action.


Solution

instead render form partial with existing project you could try something like:

new_project = existing_roject.dup
new_project.title = ""

and then render form with this object



Answered By - Igor Guzak
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing