Forum: Ruby on Rails baffled with form_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 harm (Guest)
on 2009-04-20 21:12
(Received via mailing list)
I have a simple User form with a simple Usercontroller.
The 'edit' action looks like:
  def edit
    @user = current_user
  end

In the view:
<% form_for(@user) do |f| %>
blah blah
<% end %>

What it generates is:
  <form action="/user.%23%3Cuser:0x34a498c%3E" class="edit_user"
id="edit_user_196" method="post">
  <div style="margin:0;padding:0"><input name="_method" type="hidden"
value="put" />
  <input class="inline" id="user_login" name="user[login]" size="30"
type="text" />.
  <input src="/images/buttons/registreren.png?1239978560"
type="image" />
  </form>

How does that form 'action' field becomes so b0rked?

Running Rails 2.3.2

Harm
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-21 10:54
(Received via mailing list)
On 20 Apr 2009, at 20:11, harm wrote:

> <% end %>
>  </form>
>
> How does that form 'action' field becomes so b0rked?
>
Is user an active record object ?

Fred
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 Harm (Guest)
on 2009-04-21 13:36
(Received via mailing list)
That was my initial hunch as well. And it is an AR object.

I believe that the fact that the user is a singleton resource matters.
E.g.
    map.resouce :user, :controller => "Users"

I modified the form_for and passed an explicit path with :url =>
user_path. This seems to work. But it is vert strange Rails doesn't
pick this up automatically. Then again maybe I'm defining the resource
wrong.

On Apr 21, 10:50 am, Frederick Cheung <frederick.che...@gmail.com>
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-21 16:10
Harm wrote:
> That was my initial hunch as well. And it is an AR object.
>
> I believe that the fact that the user is a singleton resource matters.
> E.g.
>     map.resouce :user, :controller => "Users"
[...]

You misspelled "resource" here.  Is it also misspelled in your actual
code?  If so, that could be the problem...

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 Harm (Guest)
on 2009-04-21 16:15
(Received via mailing list)
Ow I did misspelled it. I didn't do so in my code.

On Apr 21, 4:10 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
782b01570270ab10543bc25a258d7ea8?d=identicon&s=25 Dmitry Sokurenko (Guest)
on 2009-04-21 16:46
(Received via mailing list)
Just make users a collection (map.resources :users), then everything
will work fine. Or if your really want it to be a singleton (bad idea,
not restfull if you have more than 1 user in your app), then use
form_for :user, :object => @user.

Dmitry
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 Harm (Guest)
on 2009-04-21 16:56
(Received via mailing list)
Thank you Dmitry.
I'll ponder a bit on your remark, my initial gut feeling is that I do
want a singleton resource as I never want to expose more than 1 user.
Ever. Which is restful. But I'll think about it.

On Apr 21, 4:45 pm, Dmitry Sokurenko <Dmitry.Sokure...@gmail.com>
Ae82abddb56f9cc7864d794fa2704dd6?d=identicon&s=25 Wang Pengcheng (Guest)
on 2009-04-22 08:46
(Received via mailing list)
Most time, you can put a reference manual in your desk.
When you can't confirm the settings , you can find it very quickly.
For example :
Rails: Up and Running, Second Edition  Appendix B

http://cachefly.oreilly.com/oreilly/pdfs/978059652...
This topic is locked and can not be replied to.