hyperrjas
hyperrjas

Reputation: 10744

create new object with params from other object

I have in my controller a action with @post = Post.new

and in my view the next form:

<%= form_for(@post, :method => :get, :remote => true, :url => { :controller => "posts", :action => "new_posts_from_web" }) do |f| %>
<%= f.text_field :remote_posted_url%>
<%= f.submit "Find Images" %>

I want create in action new_posts_from_web a new post with params sent by the previous form, and I have this in new_posts_from_web action:

def new_posts_from_web
 @post = Post.new(params[:id])
end

but I get a new post without params.

How can I get params from a form in other action without save in database the object?

Upvotes: 0

Views: 2556

Answers (1)

lucapette
lucapette

Reputation: 20724

@post = Post.new(params[:post])

should work fine.

Upvotes: 2

Related Questions