I have a controller to edit titles and text_html for a given client.
route to page:
mynamespace/mycontroller/client-permalink/edit
def edit
@client = Client.find_by_permalink(params[:id])
if Title.exists?(['client_id = ? AND page_id = 10', @client.id])
@title=Title.find(:last,:conditions => ['client_id = ? AND
page_id = 10’, @client.id])
else
@title=Title.new
end
if TextHtml.exists?(['client_id = ? AND page_id = 10',
@client.id])
@text_html=TextHtml.find(:last,:conditions => [‘client_id = ?
AND page_id = 10’, @client.id])
else
@text_html=TextHtml.new
end
end
edit.html.erb:
<% form_for :client_title_text, :url => {:action => :update, :id =>
@client.permalink} do |form| %>
<% fields_for :title do |t| %>
Title: <%= t.text_field :title %><br/>
<% end %>
<% fields_for :text_html do |th| %>
Title: <%= th.text_field :text_html %><br/>
<% end %>
<%= submit_tag 'Save',:class => "submit" %>
<% end %>
My problem is that when the form submits, it looks for the client-
permalink action instead of the update action.
Relevant route:
map.namespace :mynamespace do | mynamespace |
mynamespace.resources :mycontroller
end
Models:
Client:
has_many :titles, :dependent => :destroy
has_many :text_htmls, :dependent => :destroy
Title:
belongs_to :page
belongs_to :client
TextHtml
belongs_to :page
belongs_to :client
Any ideas gratefully received,
Many thanks,
Mike