I created clean new app to test and poke around. I got to work, but I
wonder if there is still a better way to handle it and someone could
point it our.
So i have two models:
class Project < ActiveRecord::Base
has_one :task
end
class Widget < ActiveRecord::Base
belongs_to :project
validates_presence_of :project
validates_associated :project
end
widget/new view
<h1>New widget</h1>
<% form_for(@widget) do |f| %>
<%= f.error_messages %>
<%= text_field_tag :wids %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :wid %><br />
<%= f.text_field :wid %>
</p>
<p>
<div id='disp'></div>
<%= observe_field 'wids' ,:url => { :action => :find_project },
:frequency => 0.25,
:update => :disp,
:with => 'wids'
%>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', widgets_path %>
widget controller
def find_project
@project = Project.find(params[:wids])
render :partial => 'find_project'
end
_find_project view
<p>
<b>Name:</b>
<%=h @project.name %>
</p>
<%= hidden_field_tag 'widget[project_id]',@project.id %>
The piece that doesn't sit well with me is the immediate line above as
its not dynamic. Meaning if I wanted to reuse find_project method in
ajax call from other controller than widgets then I havd hard code
hidden_field_tag name for that controller as well.
Is there a better way to handle this situation?
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---