[Rails] Re: [Rails 3] Path helper not working as expected with form_for

2010-05-31 Thread Michael Jurewitz
So it would seem that there is huge level of subtly in how these path helpers 
behave based on how your pluralize the helper.  So, what I should have written 
(and what now appears to work) was:

%= form_for @thread, :as = :thread, :url = thread_message_path(@thread, 
@message) do |f| %

So that's thread_message_path, not thread_messages_path.

However, despite trying other options, it seems I still have to specify the 
HTTP verb as part of the 'new' case:

%= form_for @thread, :as = :thread, :url = thread_messages_path(@thread), 
:html = {:method = :post} do |f| %

Failing to specify :post results in the form thinking it should be PUTing 
instead of POSTing:

form action=/threads/1/messages class=thread_edit id=thread_edit 
method=postdiv style=margin:0;padding:0;display:inlineinput 
name=_method type=hidden value=put /

-Mike

On May 30, 2010, at 8:05 PM, Michael Jurewitz wrote:

 Hi there,
 
 I can't seem to get form_for to work correctly with the URL I'm providing for 
 a set of nested resources.  Here's what I'm doing in routes.rb:
 
   resources :threads do
 resources :messages
   end
 
 And then I've got the following form that I'm building as part of 
 /threads/1/messages/1/edit.  Both @thread and @message are set by the 
 controller
 
 
 %= form_for @thread, :as = :thread, :url = thread_messages_path(@thread, 
 @message) do |f| %
   %= fields_for :message do |m| %
   .
   % end %
   %= submit_tag Update Message %
 % end %
 
 This is producing the following HTML:
 
 form action=/threads/1/messages.1 class=thread_edit id=thread_edit 
 method=postdiv style=margin:0;padding:0;display:inlineinput 
 name=_method type=hidden value=put /
 
 Notice that while the HTTP method is correctly PUT, the form action ends in 
 .1 instead of /1, which is confusing the router.
 
 
 Curiously, the 'new' case seems to be getting properly constructed, though I 
 had to manually specify the :method to properly generate the URL:
 
 %= form_for @thread, :as = :thread, :url = thread_messages_path, :html = 
 {:method = :post} do |f| %
   %= fields_for :message do |m| %
   ...
   % end %
   %= submit_tag Create Reply %
 % end %
 
 
 Am I doing something obviously wrong or is this a deficiency in the path 
 convenience methods?  Note that I am using :as = all over the place 
 because the name of my model object (which is actually Axthread) does not 
 cleanly map to a named route, and using thread as a model name is not an 
 option.
 
 -Mike

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] [Rails 3] Path helper not working as expected with form_for

2010-05-30 Thread Michael Jurewitz
Hi there,

I can't seem to get form_for to work correctly with the URL I'm providing for a 
set of nested resources.  Here's what I'm doing in routes.rb:

  resources :threads do
resources :messages
  end

And then I've got the following form that I'm building as part of 
/threads/1/messages/1/edit.  Both @thread and @message are set by the controller


%= form_for @thread, :as = :thread, :url = thread_messages_path(@thread, 
@message) do |f| %
%= fields_for :message do |m| %
.
% end %
%= submit_tag Update Message %
% end %

This is producing the following HTML:

form action=/threads/1/messages.1 class=thread_edit id=thread_edit 
method=postdiv style=margin:0;padding:0;display:inlineinput 
name=_method type=hidden value=put /

Notice that while the HTTP method is correctly PUT, the form action ends in .1 
instead of /1, which is confusing the router.


Curiously, the 'new' case seems to be getting properly constructed, though I 
had to manually specify the :method to properly generate the URL:

%= form_for @thread, :as = :thread, :url = thread_messages_path, :html = 
{:method = :post} do |f| %
%= fields_for :message do |m| %
...
% end %
%= submit_tag Create Reply %
% end %


Am I doing something obviously wrong or is this a deficiency in the path 
convenience methods?  Note that I am using :as = all over the place because 
the name of my model object (which is actually Axthread) does not cleanly map 
to a named route, and using thread as a model name is not an option.

-Mike

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] [Rails 3] Trouble with named routes and form_for

2010-05-23 Thread Michael Jurewitz
Hi guys,

I'm having trouble getting named routes and form_for to play nicely in quite 
the way I would expect.  Here's a quick summary of what I've got going on:

Named route:  
resources :thread, :class_name = forum_thread

Controller name:
forum_thread_controller

Model object:
forum_thread


In both my new and edit actions I'm setting up an @thread variable:
@thread = ForumThread.new

1.)  My first attempt at writing the form_for looked something like this:

%= form_for @thread do |f| %
.
% end

This didn't work because @thread tries to use a path involving the string 
forum_thread, which doesn't have a matching route and which I don't want.  


2.)  So that's fine, I figured I'd just use named routes.  So I tried this:

%= form_for @thread, :as = :thread, :url = thread_path(@thread) do |f| %

% end 

This works for edit actions, but not for new actions.  On new I get the 
following error:

No route matches {:action=destroy, :controller=forum_thread, 
:id=#ForumThread id: nil, .}


3.)  So then I tried:

%= form_for @thread, :as = :thread, :url = threads_path(@thread) do |f| %

% end 

This doesn't work for edit, and sorta works for new except it outputs the 
following HTML, which makes the respond_to block unhappy:

form action=/thread?format= class=thread_new id=thread_new 
method=post


4.)  So then I tried:

%= form_for @thread, :as = :thread, :url = threads_path do |f| %

% end 

Now everything works for new, but not for edit!  (Because the ID of the element 
being edited isn't emitted as part of the action):

form action=/thread class=thread_edit id=thread_edit method=post


So:
1.  Is there some way to use a named route that uses a custom class name and 
still be able to reuse my form partial for both new and edit actions?  Or am I 
stuck writing two forms?
2.  Is the error I received in #2 a bug in Rails 3 or expected behavior?
3.  Is the erroneous output in #3 a bug in Rails 3 or expected behavior?


My sincere thanks in advance for your help!

-Jury

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: [Rails 3] Trouble with named routes and form_for

2010-05-23 Thread Michael Jurewitz
I've also tried

%= form_for @thread, :as = :thread %

and this results in the error:

undefined method `forum_threads_path' for 
##Class:0x0103a45098:0x01039575a0


That would seem to be a bug to me.  Shouldn't form_for be using :as = :thread 
to name that route appropriately?

-M

On May 23, 2010, at 2:52 AM, Michael Jurewitz wrote:

 Hi guys,
 
 I'm having trouble getting named routes and form_for to play nicely in quite 
 the way I would expect.  Here's a quick summary of what I've got going on:
 
 Named route:  
   resources :thread, :class_name = forum_thread
 
 Controller name:
   forum_thread_controller
 
 Model object:
   forum_thread
 
 
 In both my new and edit actions I'm setting up an @thread variable:
   @thread = ForumThread.new
 
 1.)  My first attempt at writing the form_for looked something like this:
 
 %= form_for @thread do |f| %
 .
 % end
 
 This didn't work because @thread tries to use a path involving the string 
 forum_thread, which doesn't have a matching route and which I don't want.  
 
 
 2.)  So that's fine, I figured I'd just use named routes.  So I tried this:
 
 %= form_for @thread, :as = :thread, :url = thread_path(@thread) do |f| %
 
 % end 
 
 This works for edit actions, but not for new actions.  On new I get the 
 following error:
 
 No route matches {:action=destroy, :controller=forum_thread, 
 :id=#ForumThread id: nil, .}
 
 
 3.)  So then I tried:
 
 %= form_for @thread, :as = :thread, :url = threads_path(@thread) do |f| %
 
 % end 
 
 This doesn't work for edit, and sorta works for new except it outputs the 
 following HTML, which makes the respond_to block unhappy:
 
 form action=/thread?format= class=thread_new id=thread_new 
 method=post
 
 
 4.)  So then I tried:
 
 %= form_for @thread, :as = :thread, :url = threads_path do |f| %
 
 % end 
 
 Now everything works for new, but not for edit!  (Because the ID of the 
 element being edited isn't emitted as part of the action):
 
 form action=/thread class=thread_edit id=thread_edit method=post
 
 
 So:
 1.  Is there some way to use a named route that uses a custom class name and 
 still be able to reuse my form partial for both new and edit actions?  Or am 
 I stuck writing two forms?
 2.  Is the error I received in #2 a bug in Rails 3 or expected behavior?
 3.  Is the erroneous output in #3 a bug in Rails 3 or expected behavior?
 
 
 My sincere thanks in advance for your help!
 
 -Jury

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error in Bundler with PostgreSQL and Rails3

2010-02-08 Thread Michael Jurewitz
So looks like this is an issue with the PostgreSQL install that I 
happened to snag.  I just finished blowing everything away and 
reinstalling it all from MacPorts and it's working like a charm.

Huge thanks for your hep, Gianluca!

-J

Gianluca Tessarolo wrote:
 I just try and all are working good under Ruby 1.8.7 MRI... (I did'nt
 try RVM...)
 
 I did'nt any special thing, I just install pg gem and run:
 
 rails xxx -d postgresql
 cd xxx
 I have modify config/database.yml adding = host: localhost and setting
 user / password
 rails generate scaffold user name:string published:boolean
 rake db:create
 rake db:migrate
 rails server
 
 = http://localhost:3000/users
 
 CRUD operations are all working good
 
 Hope this helps...

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Error in Bundler with PostgreSQL and Rails3

2010-02-07 Thread Michael Jurewitz
Hi there,

I'm trying to get up and running with PostgreSQL 8.4 and the Rails 3
beta.  I'm running on Ruby 1.8.7 via RVM and have installed the 'pg'
gem.  While I've been able to get the pg gem to successfully build,
whenever I create a new rails app, tell it to use Postgres, and execute
'rails server' I get the following error:

jury$ rails server
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/pg-0.8.0/lib/pg.bundle:
dlsym(0x1026ef640, Init_pg): symbol not found -
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/pg-0.8.0/lib/pg.bundle
(LoadError)
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler/runtime.rb:26:in
`require'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler/runtime.rb:25:in
`each'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler/runtime.rb:25:in
`require'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler/runtime.rb:24:in
`each'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler/runtime.rb:24:in
`require'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/bundler-0.9.3/lib/bundler.rb:70:in
`require'
  from
/Volumes/Khronos/jury/Documents/rails3/postApp/config/application.rb:6
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/railties-3.0.0.beta/lib/rails/commands.rb:36:in
`require'
  from
/Users/jury/.rvm/gems/ruby-1.8.7-p249/gems/railties-3.0.0.beta/lib/rails/commands.rb:36
  from /Volumes/Khronos/jury/Documents/rails3/postApp/script/rails:10:in
`require'
  from /Volumes/Khronos/jury/Documents/rails3/postApp/script/rails:10

I'm guessing this is either an error in bundler or ruby-pg, but would
appreciate any pointers if anyone has run into this before and worked
around it.

For that matter, has anyone out there successfully got the Rails 3 beta
and Postgres working well together?  If so, I'd love to know what you've
done.

Thanks in advance!

-J
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.