form-for

Nested resources in namespace form_for

社会主义新天地 提交于 2019-11-28 05:48:23
Problem The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::Thread and Forum::Reply respectively, located in a subfolder called "forum" under my models directory. This is in Rails 3 BETA 3. routes.rb namespace :forum do root :to => 'threads#index' resources :threads do resources :replies end end app/views/forum/replies/_form.html.haml ... - form_for [@thread, @reply] do |f| ... app/controllers/forum/replies_controller.rb ... def new @reply = Forum::Reply.new end ... Error undefined method `forum_thread_forum

Ruby on rails: singular resource and form_for

纵然是瞬间 提交于 2019-11-28 05:11:15
I want user to work with only one order connected to user's session. So I set singular resource for order routes.rb: resource :order views/orders/new.html.erb: <%= form_for @order do |f| %> ... <% end %> But when I open the new order page I get an error: undefined method `orders_path` I know, that I can set :url => order_path in form_for , but what is the true way of resolving this collision? mckeed Unfortunately, this is a bug . You'll have to set the url like you mention. = form_for @order, :url => orders_path do |f| Where does that magic path come from? It took me a lot of tracing but I

When using shallow routes, different routes require different form_for arguments

非 Y 不嫁゛ 提交于 2019-11-27 10:59:27
问题 I'm using Simple Form here, but this is an issue with normal Rails forms, too. When using shallow routes, form_for needs different arguments depending in what context it's used. Example: For editing ( http://localhost:3000/notes/2/edit ), _form.html.erb needs to have simple_form_for(@note) . But for creating a new note ( http://localhost:3000/customers/2/notes/new ) _form.html.erb needs simple_form_for([@customer, @note]) . If either receives the wrong arguments, I'll get a method not found

Ruby on rails: singular resource and form_for

让人想犯罪 __ 提交于 2019-11-27 05:30:50
问题 I want user to work with only one order connected to user's session. So I set singular resource for order routes.rb: resource :order views/orders/new.html.erb: <%= form_for @order do |f| %> ... <% end %> But when I open the new order page I get an error: undefined method `orders_path` I know, that I can set :url => order_path in form_for , but what is the true way of resolving this collision? 回答1: Unfortunately, this is a bug. You'll have to set the url like you mention. = form_for @order,

Ruby on Rails : symbol as argument in form_for

拟墨画扇 提交于 2019-11-27 05:11:47
I understand what is passed to the form_for method when doing something like : <% form_for(@user) do |f| %> ... <% end %> if @user is set in the controller. This is pretty obvious. But what happens when we pass :user , as I have seen in many examples ? <% form_for(:user) do |f| %> ... <% end %> When should I use the symbol version ? Using the symbol will generate: <form action="/users" method="post"> Using the object @user set to new you get: <form action="/users/create" class="new_user" id="new_user" method="post"> If you set @user to something else it will change the form tag generated, of

Nested resources in namespace form_for

五迷三道 提交于 2019-11-27 01:03:30
问题 Problem The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::Thread and Forum::Reply respectively, located in a subfolder called "forum" under my models directory. This is in Rails 3 BETA 3. routes.rb namespace :forum do root :to => 'threads#index' resources :threads do resources :replies end end app/views/forum/replies/_form.html.haml ... - form_for [@thread, @reply] do |f| ... app/controllers/forum/replies