使用其他对象的参数创建新对象
我的控制器中有一个带有 @post = Post.new 的操作
,在我看来,下一个表单是:
<%= 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" %>
我想在操作 new_posts_from_web 中创建一个新帖子,其参数由以前的形式,我在 new_posts_from_web 操作中有这个:
def new_posts_from_web
@post = Post.new(params[:id])
end
但我得到了一个没有参数的新帖子。
如何在其他操作中从表单获取参数而不将对象保存在数据库中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该可以正常工作。
should work fine.