Hello, I am confronted with a very strange problem which I can not solve... and God I tried a lot, lost almost a whole day, but couldn''t find an answer: The idea is to have a form both in admin and in dir, in admin there will be some more fields that is why I have twice a form. In admin the form appears, in dir the form does not appear instead "þÿ New company" why is it that the code is not interpreted and how can I solve the problem ? Thank you very much, The code here below is fairly simple as you can see... in two controllers (resp. Dir and Admin) --------------------------------- def index list render :action => ''list'' end def new @company = Company.new end def create @company = Company.new(params[:company]) if @company.save flash[:notice] = ''Company was successfully created.'' redirect_to :action => ''list'' else render :action => ''new'' end end in both views (resp. Dir and Admin) ------------------------------ <h1>New company</h1> <%= start_form_tag :action => ''create'' %> <%= render :partial => ''form'' %> <%= submit_tag "Create" %> <%= end_form_tag %> <%= link_to ''Back'', :action => ''list'' %> in both _forms (resp. Dir and admin) ------------------------------- <%= error_messages_for ''company'' %> <!--[form:company]--> <p><label for="company_name">Name</label> <%= text_field ''company'', ''name'' %></p> <p><label for="company_adline">Adline</label> <%= text_field ''company'', ''adline'' %></p> <p><label for="company_adline2">Adline2</label> <%= text_field ''company'', ''adline2'' %></p> <p><label for="company_postcode">Postcode</label> <%= text_field ''company'', ''postcode'' %></p> <p><label for="company_city">City</label> <%= text_field ''company'', ''city'' %></p> <p><label for="company_state">State</label> <%= text_field ''company'', ''state'' %></p> <p><label for="company_country">Country</label> <%= text_field ''company'', ''country'' %></p> <!--[eoform:company]--> The model Company : ------------------- class Company < ActiveRecord::Base validates_presence_of :name, :email, :url validates_uniqueness_of :email, :url validates_format_of :email, :with => %r{.@.}, :message => "not a valid email" def self.find_companies find(:all, :order => "name") end end -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I can''t see your partials However, partials are relative to the current controller. <%= render :partial => ''form'' %> works for admin if the file _form.rhtml is located in the /views/admin folder. Change it to this <%= render :partial => ''admin/form'' %> and let me know if that works for you :) On 11/28/06, Ja Bo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > > I am confronted with a very strange problem which I can not solve... and > God I tried a lot, lost almost a whole day, but couldn''t find an answer: > The idea is to have a form both in admin and in dir, in admin there will > be some more fields that is why I have twice a form. In admin the form > appears, in dir the form does not appear instead > "þÿ > New company" why is it that the code is not interpreted and how can I > solve the problem ? > > Thank you very much, > > The code here below is fairly simple as you can see... > > in two controllers (resp. Dir and Admin) > --------------------------------- > def index > list > render :action => ''list'' > end > > def new > @company = Company.new > end > > def create > @company = Company.new(params[:company]) > if @company.save > flash[:notice] = ''Company was successfully created.'' > redirect_to :action => ''list'' > else > render :action => ''new'' > end > end > > in both views (resp. Dir and Admin) > ------------------------------ > <h1>New company</h1> > > <%= start_form_tag :action => ''create'' %> > <%= render :partial => ''form'' %> > <%= submit_tag "Create" %> > <%= end_form_tag %> > > <%= link_to ''Back'', :action => ''list'' %> > > in both _forms (resp. Dir and admin) > ------------------------------- > <%= error_messages_for ''company'' %> > > <!--[form:company]--> > <p><label for="company_name">Name</label> > <%= text_field ''company'', ''name'' %></p> > > <p><label for="company_adline">Adline</label> > <%= text_field ''company'', ''adline'' %></p> > > <p><label for="company_adline2">Adline2</label> > <%= text_field ''company'', ''adline2'' %></p> > > <p><label for="company_postcode">Postcode</label> > <%= text_field ''company'', ''postcode'' %></p> > > <p><label for="company_city">City</label> > <%= text_field ''company'', ''city'' %></p> > > <p><label for="company_state">State</label> > <%= text_field ''company'', ''state'' %></p> > > <p><label for="company_country">Country</label> > <%= text_field ''company'', ''country'' %></p> > > <!--[eoform:company]--> > > The model Company : > ------------------- > class Company < ActiveRecord::Base > validates_presence_of :name, :email, :url > validates_uniqueness_of :email, :url > validates_format_of :email, > :with => %r{.@.}, > :message => "not a valid email" > > def self.find_companies > find(:all, :order => "name") > end > end > > -- > 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> I can''t see your partials > However, partials are relative to the current controller. > > <%= render :partial => ''form'' %> works for admin if the file > _form.rhtml > is located in the /views/admin folder. > > Change it to this > > <%= render :partial => ''admin/form'' %> > > and let me know if that works for you :)Thank you very much for your quick reply. Thank you also for the very handy tip to use a "centralized" form. I seems that I have to get used to program in a non-repetitive way.. The funny part is that the ''admin'' routine works like a charm, whereas the ''dir'' routine gives me the error, although they both refer to the same form, use exactly the same definition in their respective controller and have the same view files as well ! If I look in the source file that is generated, I can still see the ruby code, so the code is not interpreted... This is particulary strange, as I for test purposes copied the view file from admin to dir, and also copy pasted the def. in the controllers.. Hope that makes it clearer... BTW I want to have separate controller definitions, because in a later phase I will add fields to the ''admin'' view that shouldn''t be accessible by the user.. I thought that the dir_controller couldn''t access the company data, but for displaying it, like in the ''list'' routine it can.. the mystery isn''t solved yet, but my code looks nicier already..., Anyone ? jabo -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---