[Rails] How to use partition
Hi Folks, Real easy one for you probably. I'm just trying to split an array in half into 2 separate arrays that I can loop through and have seen the Partition method. Can anyone give me an example of how to use this, as I don't quite understand what it means by having a true_array and a false_array!? Thanks a lot guys -- 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@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: radio buttons?
Frederick Cheung wrote: > On 15 Apr 2009, at 12:54, Dave Smith wrote: > >>>> <%= f.radio_button :published_at, false %> No >> i was actually hoping for when they check the yes option is puts the >> current time in the field. and when they click no it is removed. > > Ah, so that's more than a radio button. it's some radio buttons + your > favourite date input method, together with a chunk of javascript that > does stuff to those input controls. > The radio_button would be for a separate attribute (which might not > even be a real one) to published_at > > Fred ahh ok! thanks, is that much more difficult to implement? i have searched for examples online and in my rails books but cannot find anything. -- 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@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: radio buttons?
Frederick Cheung wrote: > On 15 Apr 2009, at 12:05, Dave Smith wrote: > >> >> if i got a couple of radio buttons on my form that i want to use a >> published_at field rather than a boolean field how would i go about >> this? I know that if i'm using a boolean i can do the following. >> >> <%= f.radio_button :published_at, true %> Yes >> <%= f.radio_button :published_at, false %> No >> >> but what would i have to change to use the datetime field? >> > Are you expecting people to enter a date or to choose between one of > several dates ? > > Fred Hi, i was actually hoping for when they check the yes option is puts the current time in the field. and when they click no it is removed. -- 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@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] radio buttons?
if i got a couple of radio buttons on my form that i want to use a published_at field rather than a boolean field how would i go about this? I know that if i'm using a boolean i can do the following. <%= f.radio_button :published_at, true %> Yes <%= f.radio_button :published_at, false %> No but what would i have to change to use the datetime field? many thanks in advance guys, -- 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@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: baffled on forms and controllers!!
dont worry. fixed. replaced form_for with form_tag -- 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@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] baffled on forms and controllers!!
Hi Chaps, Having a little issue with my date filter business here, ive got a date_filter (something i added to my form builder - which works by the way) in my page, and I want to use it to filter my @articles. in my page. <% form_for @date_filter do |f| %> <%= f.date_field :before %> <%= f.date_field :after %> <% end %> in my ruby class... class DateFilter attr_accessor :before, :after def initialize(attributes) attributes.each { |k,v| self.send("#{k}=", v) } end end and in my controller... @date_filter = DateFilter.new(params[:date_filter]) @articles = @results.find(:all, :conditions => [ "created_at >= ? and created_at <=?", @filter.before, @filter.after], :order => 'created_at desc', :page => {:size => 5, :current => params[:page]}) but I am receiving the following error... ActionView::TemplateError (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id) on line #24 of admin/articles/index.html.erb: 21: Filter by: Date 22: Between 23: 24: <% form_for @date_filter do |f| %> 25: <%= f.date_field :before %> 26: <%= f.date_field :after %> 27: <% end %> Perhaps someone could help me to see whats going wrong... Many thanks in advance -- 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@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] CHECK if param exists? please help
hi folks. i want to check if a param exists if not to set it to a default value for my date range filter. in my controller i have: @from_date = Date.strptime(params[:startdate],"%d/%m/%Y") @to_date = Date.strptime(params[:enddate],"%d/%m/%Y") @articles = @results.find(:all, :conditions => [ "created_at >= ? and created_at <=?",@from_date,@to_date], :order => 'created_at desc', :page => {:size => 5, :current => params[:page]}) this works as long as i have the params in the query string in the address. but if i remmove them i want to be able to default to a date range from today back a couple of months. is there a param[:startdate].exists? check i can do??? any help asap would be great!! -- 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@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: date filter
Norm wrote: > Dave Smith wrote: >> anyone know any examples of good code for a date range filter i can add >> to my app to return only selected articles within that range based on >> their created at date. >> > > Here is how I fetch something similar. It is just a simple find. > Substitute the created_at field and it should work. Is that what you > are looking for? > > @res = Reservation.find(:all, > :conditions => [ "enddate >= ? and startdate > <= ?",Date.today,Date.today+120], > :order => "space_id,startdate ASC") ok thats great but how do I initiate that from the code. so for example the page will load index and collect the articles normally. but how do i then get it to collect the articles using the date filter code here!? sorry for such a noob question -- 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@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: date filter
Dave Smith wrote: > > sorry... @articles.in_period(@start_date, @end_date) anyone have any idea? -- 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@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: date filter
sorry... @articles.in_period(@start_date, @end_date) -- 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@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: date filter
> > and examples on the net state the same, but I want to be able to input > two dates into boxes and call the filter from the view page, which I > also am not sure how to do. > > any help would be greatly appreciated. > > dave im pretty sure this would work. But am wondering how I can call this filter from my page. so for example have two text boxes and a button that calls somthing similar to " @article.comments.in_period(@start_date, @end_date)" named_scope :in_period, lambda { |start_date, end_date| { :conditions => ["articles.created_at >= ? and " + "articles.created_at <= ?", start_date, end_date] } any ideas? -- 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@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: date filter
Tranquiliste wrote: > Hello > > You could use named_scope (starting with rails 2.1). > > There is a good rails cast presenting them with an example with > dates : http://railscasts.com/episodes/108-named-scope Hi, thanks for the response. I am wondering how to do this in my app. I can see the example code named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } } and examples on the net state the same, but I want to be able to input two dates into boxes and call the filter from the view page, which I also am not sure how to do. any help would be greatly appreciated. dave -- 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@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] date filter
anyone know any examples of good code for a date range filter i can add to my app to return only selected articles within that range based on their created at date. -- 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@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: quick answer needed on dependancy
Dave Smith wrote: > > mailinglist = Mailinglist.mail_template_mailinglists.find(:all, > :conditions => ["mail_template_id = ?", params[:id]]) > > if mailinglist.empty? > MailTemplate.find(params[:id]).destroy > else > flash[:notice] = 'Cannot delete mail template, as it is being used > by one or more mailinglist.' > end > > > > NoMethodError in Admin/mail templatesController#destroy > > undefined method `mail_template_mailinglists' for # any ideas anyone? -- 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@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] quick answer needed on dependancy
Hi Guys, I have a mail_templates table I have a mailinglists table I have a mail_templates_mailinglists table with mailtemplate_id, and mailinglist_id mail_template has_and_belongs_to_many :mailinglists mailinglist has_and_belongs_to_many :mail_templates, :foreign_key => "mailinglist_id" I want to be able to stop the user being able to destroy the mail_template if it is being used by a mailinglist. So in my destroy method in my mail_template controller I want to find any mailinglists that have a mail_template id. I tried the following but I am getting an error, mailinglist = Mailinglist.mail_template_mailinglists.find(:all, :conditions => ["mail_template_id = ?", params[:id]]) if mailinglist.empty? MailTemplate.find(params[:id]).destroy else flash[:notice] = 'Cannot delete mail template, as it is being used by one or more mailinglist.' end NoMethodError in Admin/mail templatesController#destroy undefined method `mail_template_mailinglists' for # -- 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@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: radio buttons and whatnot
Dave Smith wrote: > >> <% form_for(@project) do |f| %> >> <% for task in @project_tasks %> >> <%= render :partial => "statuses", :locals => { :f => f } %> >> <% end %> >> <% end %> >> >> I want it to take the task object instead >> >> any ideas? > > bump dont worry i fixed it. just moved the form into the loop cheers guys -- 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@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: radio buttons and whatnot
> <% form_for(@project) do |f| %> > <% for task in @project_tasks %> > <%= render :partial => "statuses", :locals => { :f => f } %> > <% end %> > <% end %> > > I want it to take the task object instead > > any ideas? bump -- 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@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: radio buttons and whatnot
Ar Chron wrote: > In your case, have the appropriate controller read in the statuses info > and hand that to the view... > > @statuses = Status.find(:all, :order => 'something') > > Then the view (or a partial) can do something like: > > @statuses.each do |this_status| > radio_button("application", "status", this_status.value) > end > > or sumfink like that... brill... i understand. what i have done it put it in a partial in my page form. I have a projects page with a list of project_tasks and I want to use the same code in this page and have the status in the form of a radio button for each task, so I have put the code into a partial in projects view. This is my partial. <% Status.find_all_by_type("Project").each do |s|%> <%= f.radio_button :status_id, s.id %> <%= f.label :status_id, s.name %> <% end %> I am trying to make a link to the partial on the projects show.html.erb page. I know the code below this will not work, but am trying to adapt it to take the task instead of the project form object. <%= render :partial => "statuses", :locals => { :f => f } %> obviously my partial here will be expecting a project form object.. any clues? <% form_for(@project) do |f| %> <% for task in @project_tasks %> <%= render :partial => "statuses", :locals => { :f => f } %> <% end %> <% end %> I want it to take the task object instead any ideas? -- 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@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: radio buttons and whatnot
Dave Smith wrote: > Hey guys, > > I got a statuses model which holds all my applications statuses, they > are differentiated by their status type. > > In my application I have some invoices that I want to be able to set > their invoice.status using radio buttons (which are created in my view > from the statuses table). > > Does anyone have any idea on how to achieve this, as there appears to be > little help available online for such things. > > thanks a bunch > > dave nay ideas? -- 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@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] radio buttons and whatnot
Hey guys, I got a statuses model which holds all my applications statuses, they are differentiated by their status type. In my application I have some invoices that I want to be able to set their invoice.status using radio buttons (which are created in my view from the statuses table). Does anyone have any idea on how to achieve this, as there appears to be little help available online for such things. thanks a bunch dave -- 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@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: Pre Custom Objects and Stuff - Easy Answer im sure
Dave Smith wrote: > Hi Guys, > > When I create a project I would like to be able to create a default set > of tasks for that project. > > One could have a line for each task to manually add each project_task in > the projects controller when creating the project but that would be poor > programming im sure.! > > Is there a way of achieving this, perhaps making pre-customised objects > in a config file or something? > > Cheers Folks, > > Dave Any ideas guys? -- 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@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] Pre Custom Objects and Stuff - Easy Answer im sure
Hi Guys, When I create a project I would like to be able to create a default set of tasks for that project. One could have a line for each task to manually add each project_task in the projects controller when creating the project but that would be poor programming im sure.! Is there a way of achieving this, perhaps making pre-customised objects in a config file or something? Cheers Folks, Dave -- 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@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: Anyone Recommend a File Uploader
Sazima wrote: > attachment_fu, file_column, paperclip (nice railscast) > > Ifo you need multiple concurrent uploads, go for something in flash... > > Cheers, Sazima > > On Jan 7, 12:13�pm, Dave Smith thank you all for your help! its greatly appreciated! ive gone with another method of multiple attachments using attachment fu, and am learning fat models and skinny controllers to help in general. http://www.practicalecommerce.com/blogs/post/432-Multiple-Attachments-in-Rails cheers folks dave -- 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@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: Anyone Recommend a File Uploader
> > And to be honest, this is not really good code either. > > You are manually assigning related record ids instead of relying on > Rails' built-in safeguards. > > I'd advise u to start looking at railscasts.com, starting for very > early ones (complex forms might be a good one for you), getting a > Rails book (The Rails Way, Agile Web Development with Rails) and > getting to know the framework better. > > > Best regards > > Peter De Berdt Hi Peter, Many thanks for your extensive help on this one. I now have @project_file = ProjectFile.new(params[:project][:uploaded_data]) in my projects controller. <%= f.file_field :uploaded_data %> but it still says ActiveRecord::UnknownAttributeError in ProjectsController#create unknown attribute: uploaded_data -- 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@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: Anyone Recommend a File Uploader
Peter De Berdt wrote: > On 08 Jan 2009, at 15:33, Dave Smith wrote: > >>@project_file = Project_File.new(params[:uploaded_data]) > > ProjectFile seems more like an ActiveRecord class name. > > > Best regards > > Peter De Berdt You'll have to excuse me for my lack of knowledge here but I dont understand? -- 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@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: Anyone Recommend a File Uploader
does anyone have any ideas? projects controller def create @project = Project.new(params[:project]) @project.company_id = get_user.company.id @project.status_id = 2 @project_file = Project_File.new(params[:uploaded_data]) respond_to do |format| if @project.save flash[:notice] = 'Project was successfully created.' format.html { redirect_to(@project) } format.xml { render :xml => @project, :status => :created, :location => @project } else format.html { render :action => "new" } format.xml { render :xml => @project.errors, :status => :unprocessable_entity } end end end new project view <% form_for(@project, :html => {:multipart => true}) do |f| %> <%= f.error_messages %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :description %> <%= f.text_field :description %> <%= f.label :date_due %> <%= f.calendar_date_select :date_due %> <%= f.file_field :uploaded_data %> <%= f.submit "Create" %> <% end %> <%= link_to 'Back', projects_path %> project_file model belongs_to :project has_attachment :storage => :file_system, :path_prefix => 'public/files', :partition => false validates_as_attachment error message ActiveRecord::UnknownAttributeError in ProjectsController#create unknown attribute: uploaded_data RAILS_ROOT: /Users/louisbacon/Sites/codepress Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2587:in `attributes=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `each' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `attributes=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2283:in `initialize' app/controllers/projects_controller.rb:61:in `new' app/controllers/projects_controller.rb:61:in `create' thanks a bunch -- 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@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: Anyone Recommend a File Uploader
> > <%= f.label :description %> > <%= f.text_field :description %> > > > <%= f.label :date_due %> > <%= f.calendar_date_select :date_due %> > > > <%= f.file_field :uploaded_data %> > > > <%= f.submit "Create" %> > > <% end %> i forgot to state, that i already had the multipart code in there. so i dont thin the problem is that -- 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@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: Anyone Recommend a File Uploader
> Example: ><% form_for(:attachment_metadata, :url => { :action => > "create" }, :html => { :multipart => true }) do |form| %> > >2. Use the file_field helper with :uploaded_data as the field name. > Example: ><%= form.file_field :uploaded_data %> > > I suspect you didn't include the multipart option. > > > Best regards > > Peter De Berdt Hi Peter, Many thanks for your answer, I have included this in my code. This is my entire new.html.erb file. <% form_for(@project, :html => {:multipart => true}) do |f| %> <%= f.error_messages %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :description %> <%= f.text_field :description %> <%= f.label :date_due %> <%= f.calendar_date_select :date_due %> <%= f.file_field :uploaded_data %> <%= f.submit "Create" %> <% 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@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: Anyone Recommend a File Uploader
MaD wrote: >> I guess here's the latest >> version:http://github.com/technoweenie/attachment_fu/tree/master > > oh, i'm sorry. i still got some old bookmarks on svn instead of github. perfect, got it installed and trying to figure out how to get it working.. project controller in create, @project_file = Project_File.new(params[:uploaded_data]) in project view, <%= f.file_field :uploaded_data %> the page loads and i can select a file but when i go to save im getting the error, ActiveRecord::UnknownAttributeError in ProjectsController#create unknown attribute: uploaded_data project has_many :project_files project_file belongs_to :project any ideas? -- 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@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: Quick one! -- Project Messages!!
Dave Smith wrote: > >>> - >>> Ryan Bigg >>> Freelancer >>> http://frozenplague.net >> >> Thanks for your help. >> >> Ive created a nested route, and now have my messages for the project >> which is fine. The next problem comes from getting the comments for each >> message in this index page. >> >> I am not quite sure how I can retrieve the comments per message in the >> index in my controller > > any ideas at all? i am having the same problem as this for another part of the system. i need to collect on the projects index page a list of the invoices associated with that project but am unsure how to do this. It is easy on the view page as you can loop through and collect them, but how can I do this on the index page? The answer to this will answer the previous questions as well..! -- 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@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] Anyone Recommend a File Uploader
Can anyone recommend a good file upload plugin for uploading standard files (more than one file per article / project), but I am not interested in images or image processing, just a standard uploader for files! -- 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@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: relationships quickie
Franz Strebel wrote: > On Wed, Jan 7, 2009 at 12:13 PM, Dave Smith > wrote: >> >> i have a project. >> >> the project has a status_id. >> >> i have a statuses table with id's and names. >> >> the project model includes "has_one :status" > > try belongs_to :status i understand now! cheers guys -- 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@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] relationships quickie
i have a project. the project has a status_id. i have a statuses table with id's and names. the project model includes "has_one :status" the status model includes "has_many :projects" in my projects index page instead of project.status_id displaying 1, 2 or 3 i want to have the statuses.name accosiated with that id. i tied putting <%= project.status.name %> but i get the error, SQLite3::SQLException: no such column: statuses.project_id: SELECT * FROM "statuses" WHERE ("statuses".project_id = 6) LIMIT 1 it appears to be looking in statuses table for project_id not the other way around. can anyone clear this up for me? cheers, dave -- 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@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: Quick one! -- Project Messages!!
>> - >> Ryan Bigg >> Freelancer >> http://frozenplague.net > > Thanks for your help. > > Ive created a nested route, and now have my messages for the project > which is fine. The next problem comes from getting the comments for each > message in this index page. > > I am not quite sure how I can retrieve the comments per message in the > index in my controller any ideas at all? -- 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@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: Quick one! -- Project Messages!!
Ryan Bigg wrote: > Woah. > > Firstly, why are you calling .collect on project.messages and > everything? This is unnecessary. > > Secondly, if messages is an association for a project it would be > better if you used nested routes, as explained here: > http://guides.rails.info/routing_outside_in.html > . Your controller would be called messages_controller and the action > would be called index, not messages. > - > Ryan Bigg > Freelancer > http://frozenplague.net Thanks for your help. Ive created a nested route, and now have my messages for the project which is fine. The next problem comes from getting the comments for each message in this index page. I am not quite sure how I can retrieve the comments per message in the index in my controller -- 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@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: Quick one! -- Project Messages!!
Sazima wrote: > 1. Route (config/routes.rb): > > map.with_options(:controller => 'messages') do |m| > m.messages '/messages', :action => 'messages' > end > > 2. Action (app/controllers/messages_controller.rb): > > def messages > # Retrieve messages the same way you did in the index action > end > > 3. View (app/views/messages/messages.html.erb) => do the same as in > index, but showing the whole message... > > Cheers, Sazima > > On Jan 5, 3:20�pm, Dave Smith im slightly confused. i was returning the messages in the projects controller by doing @project_messages = @project.messages.collect -- 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@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: Quick one! -- Project Messages!!
Sazima wrote: > If this 2nd page you want will contain only 1 message, then it is the > standard show action + view... Otherwise you can add a named route and > use whatever name you want for the action and view. But it can be > trickier to add comments. > > Cheers, Sazima > > On Jan 5, 3:05�pm, Dave Smith ok if for now i say i just want all messages, no comments. how would i go about adding the named route and view? -- 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@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: Quick one! -- Project Messages!!
Sazima wrote: > Do you want the second page to contain all the messages or just 1 > message? > > Cheers, Sazima > > On Jan 5, 8:40�am, Dave Smith ? -- 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@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: Quick one! -- Project Messages!!
Dave Smith wrote: > Sazima wrote: >> Do you want the second page to contain all the messages or just 1 >> message? >> >> Cheers, Sazima >> >> On Jan 5, 8:40�am, Dave Smith > > all the messages for a particular project, and then a section under for > comments to be made for each message (kind of indented if you know what > i mean) i just thought i could create a partial and reference to it from both the project view page and another page such by passing in the project id somehow. -- 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@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: Quick one! -- Project Messages!!
Sazima wrote: > Do you want the second page to contain all the messages or just 1 > message? > > Cheers, Sazima > > On Jan 5, 8:40�am, Dave Smith all the messages for a particular project, and then a section under for comments to be made for each message (kind of indented if you know what i mean) -- 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@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: Quick one! -- Project Messages!!
Bobnation wrote: > What did you name the method in your project controller? > > On Jan 5, 5:40�am, Dave Smith Hi, Im not sure if I am going about this the right way but, ive created a partial called _message in the project view with the following link; -- <% for message in @project_messages %> <%= render :partial => "message", :object => message %> <% end %> -- and the following code in the _message partial. <%= message.status %> - <%= message.title %> <%= truncate(message.body, 60, "...") %> <%= link_to 'continue...', message_path(@project) %> This works to view the messages within the project view page. But I want to be able to view all the messages for a project in thier entirety on a different page and create comments for each message... My Projects controller show def currently looks like this; def show @project = Project.find(params[:id]) @project_tasks = @project.tasks.collect @project_messages = @project.messages.collect respond_to do |format| format.html # show.html.erb format.xml { render :xml => @project } 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@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: Quick one! -- Project Messages!!
> In my project view page you can see the messages (but they are truncated > to save space). I want to have a "more" link that takes the user to > another page which holds all the full project messages. > > Do I create a page called messages.html.erb? > > I would also like to be able to comment on each of the messages on the > second page!?!? > > Please can someone help me as I am a really stuck! > > Thank you very much!! > > Dave Anyone? -- 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@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] Quick one! -- Project Messages!!
Hi Guys, The answer to this is probably pretty simple but I have an app which holds projects, and have messages for each project. project has_many messages message belongs to project in my project controller i just do @project_messages = @project.messages.collect In my project view page you can see the messages (but they are truncated to save space). I want to have a "more" link that takes the user to another page which holds all the full project messages. Do I create a page called messages.html.erb? I would also like to be able to comment on each of the messages on the second page!?!? Please can someone help me as I am a really stuck! Thank you very much!! Dave -- 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@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: Passing aariable from controller to a different view ???
Ryan Bigg wrote: > Use restful authentication (or a similar plugin) for tracking that > kind of stuff: http://github.com/technoweenie/restful_authentication > - > Ryan Bigg > Freelancer > http://frozenplague.net Couldnt I just do the following... in my projects controller? before_filter :find_projects def index # @projects = Project.find(:all) # @project_company = @projects.company_id @projects = @results.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @projects } end end def find_projects @user_in = Person.find_by_id(session["user_id"]) @company = Company.find_by_id(@user_in.company_id) @results = Company.find(@company.id).projects # Find all projects that belong to company 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@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] Passing aariable from controller to a different view ????
Hi Guys, I am still very new to this rails stuff so I'm looking for some help. I have a login controller which authenticates a person and redirects them to the projects page, here is a snippet of code. == if request.post? person = Person.authenticate(params[:email_address], params[:password]) if person session["user_id"] = person.id if person.type == "Customer" flash[:notice] = "You have successfully logged in" redirect_to(:controller => "projects", :action => "index" ) end else redirect_to :action => "login" flash[:notice] = "Invalid user/password combination" end end == I have a projects controller which has a field company_id (as a project belongs to a company). I also have a people table which holds the customers (as well as admins based on person.type). I want to be able to redirect the person to the projects table and have the projects displayed only for that user. In the customer model I have specified belongs_to :company. In the project model I have also specified belongs_to :company. In the company model I have specified has_many :projects. Somehow I need to get the person logging in from the login controller and transfer that to company controller and then pass that to the the projects controller to use in the project view. But I have really stuck on how to do this! Please can someone help! Regards, Dave -- 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@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: application security fun
Frederick Cheung wrote: > On 11 Dec 2008, at 11:47, Dave Smith wrote: > >> >> I currently only have customer and admin controllers. Do i need to >> create a people controller? or can i reference the database from the >> login controller? >> > controllers aren't tied to models. Any controller can use any model to > do anything. > > Fred excellent.. sorted.. cheers -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] application security fun
Hello, I am trying to develop an application that uses STI for People. So you have customer < person, admin < person. I have also created a login controller with accompanying simple login page (un & pw fields). -- Login Controller def do_login username = params[:username] password = params[:password] if username.nil? || password.nil? || username==password redirect_to :action => "login" flash[:notice] = 'Unknown user or invalid password' else session["user_id"] = username redirect_to :controller => "customers", :action => "index" end --- Currently it just checks if something is entered into the boxes to test that it works. I have created a register page that adds a record to the database table people an email address, hashed password, and salt. What i want to do is check these when a user enters a username and password in the login page but am not quite sure what to do. I currently only have customer and admin controllers. Do i need to create a people controller? or can i reference the database from the login controller? Any help would be great !!! Regards, Dave -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: names and nested routes?!?
Franz Strebel wrote: > On Mon, Dec 8, 2008 at 1:55 PM, Dave Smith > <[EMAIL PROTECTED]> wrote: >> >> http://localhost:3000/services/clothes/articles > > Assuming that the attribute of the Service is called name, > you should define this in your Service model: > > def to_param > name > end > > for more info, look at this post: > > http://www.jroller.com/obie/entry/seo_optimization_of_urls_in I used the following code in the end, as I have a field title in the table. def to_param id.to_s+'-'+title.downcase.gsub(' ', '-') end However it puts the address with the ID at the beginning; http://localhost:3000/services/1-horse-&-groom/articles Is there a way I can remove this from the address to tidy it up a bit? -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] names and nested routes?!?
Hi Guys, I have the following route to show the articles for a selected service in my application. http://localhost:3000/services/4/articles I want to be able to have a route to the service name rather than the route such as the following. http://localhost:3000/services/clothes/articles I thought something like the following in the routes.rb file would be the way forward? map.connect 'clothes/', :controller => 'articles', :action => "index", :service_id => '4' Many thanks in advance Dave -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: image text link instead of image_for help!
Frederick Cheung wrote: > On Dec 4, 2:37�pm, Dave Smith <[EMAIL PROTECTED]> > wrote: >> Frederick Cheung wrote: > >> As a quick secondary question, I was wondering why when I have a button >> to delete the image from the database it works perfectly in the >> edit.html.erb file, but when I move the button into the _form.html.erb >> file so that it sits next to the other image related elements the >> @article_image.id value is not passed accross... in fact I dont think it >> even is picked up in the first place. > > Probably because behind the scenes the button helper creates a form > and you can't nest forms > > Fred booger is there a potential workaround? -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: image text link instead of image_for help!
Frederick Cheung wrote: > On 4 Dec 2008, at 13:53, Dave Smith wrote: > >>>> >># link_to image_tag(article_img), >> article.article_image.public_filename >> >> link_to 'click me', article_img, >> article.article_image.public_filename > > Well you are. > Just > link_to 'click me', article_img > > is quite enough. > > Fred OK I understand now. As a quick secondary question, I was wondering why when I have a button to delete the image from the database it works perfectly in the edit.html.erb file, but when I move the button into the _form.html.erb file so that it sits next to the other image related elements the @article_image.id value is not passed accross... in fact I dont think it even is picked up in the first place. <%= button_to "Delete Image", { :action => "delete_article_image", :article_image_id => @article_image.id } %> def delete_article_image @article_image = ArticleImage.find(params[:article_image_id]) @article_image.destroy respond_to do |format| format.html { redirect_to(admin_articles_url) } format.xml { head :ok } end end As is the code for the button works on the edit page (which holds the partial _form) but sits outside the rest of the elements and looks rediculous having a "delete image" button at the bottom of the page. -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: image text link instead of image_for help!
Frederick Cheung wrote: > On 4 Dec 2008, at 13:36, Dave Smith wrote: > >>>> "/article_images//0047/Photo_59.jpg":String >>>> Extracted source (around line #12): >>>> >>> What's the rest of that stack trace? >>> >>> Fred >> > looks like you're passing that string to link_to twice. > > Fred ummm interesting... module Admin::ArticlesHelper def article_image_for(article) if article.article_image article_img = article.article_image.public_filename # link_to image_tag(article_img), article.article_image.public_filename link_to 'click me', article_img, article.article_image.public_filename #else #image_tag("blank-image.png") end end end this is my adapted articles helper method... -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: image text link instead of image_for help!
Frederick Cheung wrote: > On 4 Dec 2008, at 13:14, Dave Smith wrote: > >>> >> i have made changes but now get the error... >> >> Showing admin/articles/edit.html.erb where line #12 raised: >> >> undefined method `stringify_keys' for >> "/article_images//0047/Photo_59.jpg":String >> Extracted source (around line #12): >> > What's the rest of that stack trace? > > Fred c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/url_helper.rb:201:in `link_to' app/helpers/admin/articles_helper.rb:6:in `article_image_for' app/views/admin/articles/_show.html.erb:7:in `_run_erb_47app47views47admin47articles47_show46html46erb' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partial_template.rb:20:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:26:in `benchmark' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/benchmark.rb:8:in `realtime' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:26:in `benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partial_template.rb:19:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:22:in `render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partials.rb:110:in `render_partial' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:277:in `render' app/views/admin/articles/index.html.erb:26:in `_run_erb_47app47views47admin47articles47index46html46erb' vendor/plugins/paginating_find/lib/paging_enumerator.rb:45:in `each' vendor/plugins/paginating_find/lib/paging_enumerator.rb:45:in `each' app/views/admin/articles/index.html.erb:24:in `_run_erb_47app47views47admin47articles47index46html46erb' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:35:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:22:in `render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:248:in `render_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1112:in `render_for_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:869:in `render_with_no_layout' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:884:in `render_with_no_layout' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/layout.rb:251:in `render_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in `render' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/benchmark.rb:8:in `realtime' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in `render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:131:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:131:in `custom' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:160:in `call' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:160:in `respond' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:154:in `each' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:154:in `respond' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:107:in `respond_to' app/controllers/admin/articles_controller.rb:16:in `index' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `perform_action_without_filters' c:/ruby/
[Rails] Re: image text link instead of image_for help!
Frederick Cheung wrote: > On Dec 3, 11:00�am, denver <[EMAIL PROTECTED]> wrote: > >> def article_image_for(article) >> � � � � if article.article_image >> � � � � � � article_img = article.article_image.public_filename >> � � � � � � link_to image_tag(article_img), >> article.article_image.public_filename > > Is it not as simple as changing the above to > link_to 'click me', article_img > > ? > > > Fred i see what you mean... i have made changes but now get the error... Showing admin/articles/edit.html.erb where line #12 raised: undefined method `stringify_keys' for "/article_images//0047/Photo_59.jpg":String Extracted source (around line #12): 9: 10: <% end %> 11: <% if(@article.article_image) %> 12: <%= article_image_for(@article) %> 13: 14: 15: -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
> Application Trace | Framework Trace | Full Trace > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:253:in > > `load_missing_constant' > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in > > `const_missing' > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in > > `send' > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in > > `const_missing' > app/controllers/admin/mailinglists_controller.rb:116:in `send_mail' > app/controllers/admin/mailinglists_controller.rb:115:in `send_mail' > app/controllers/admin/mailinglists_controller.rb:114:in `send_mail' > Request > > Parameters: > > {"authenticity_token"=>"dc9249eaed248ed10c939b4b0fd52c0c373c5f09", > "id"=>"1"} > Show session dump dont worry, i fixed it by prepending Admin:: to the reference of the model.. but out of curiosity, why did it work the first time and not the second time? -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On Dec 3, 1:27�pm, Dave Smith <[EMAIL PROTECTED]> > wrote: >> > over all templates in the controller. >> I presume somthing similar to this would work >> >> [EMAIL PROTECTED] = Mailinglist.find(params[:id]) >> � � @mail_templates = @mailing_list.mail_templates.collect >> > collect with no block does nothing > >> � � @mail_templates.mail_templates.each do |mail_template| > > Just @mailing_list.mail_templates.each ... > will do here, assuming mailing_list has_many mail_templates > > Fred brilliant, thank you Fred. I have the code working without syntax errors. There is however a problem where it will only work once in both loops. for example if i have more than one email address in the mailinglist, or more than one template it sends the first email to me no problem but then throws the following error ArgumentError in Admin/mailinglistsController#send_mail Admin is not missing constant Emailer! RAILS_ROOT: C:/ruby/myprojects/service Application Trace | Framework Trace | Full Trace c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:253:in `load_missing_constant' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in `const_missing' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in `send' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in `const_missing' app/controllers/admin/mailinglists_controller.rb:116:in `send_mail' app/controllers/admin/mailinglists_controller.rb:115:in `send_mail' app/controllers/admin/mailinglists_controller.rb:114:in `send_mail' Request Parameters: {"authenticity_token"=>"dc9249eaed248ed10c939b4b0fd52c0c373c5f09", "id"=>"1"} Show session dump -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On Dec 3, 1:07�pm, Dave Smith <[EMAIL PROTECTED]> > wrote: > >> now this i know is poor programming and looks bad too.. is there a way i >> can just have one button that sends each of the mail templates to all >> the users in the list..? > > just call the action something like send_all_mails or something like > that and drop the :mail_template_id parameter and do that iteration > over all templates in the controller. > > If you wanted to get a bit more fancy then you could have a checkbox > for each template you want to send (whether you have a list of > templates with a checkbox for each mailing list that should receive it > or a list of mailing list with checkboxes for each template that > should go to a given mailing list is down to what makes the most > business sense to you) > > Fred I presume somthing similar to this would work @mailing_list = Mailinglist.find(params[:id]) @mail_templates = @mailing_list.mail_templates.collect @mail_templates.mail_templates.each do |mail_template| @mailing_list.mailings.each do |mailing| Emailer.deliver_contact(mailing.email_address, @mail_template.name, @mail_template.content) 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On 2 Dec 2008, at 13:26, Dave Smith wrote: > >>>>> Fred >>> button_to :send_mail, :id => some_template.id, :mailing_list_id => >>> end >> mailings (database table shown below). >>@mail_template = MailTemplate.find(params[:id]) >>@mailing_list = MailingList.find(params[:mailing_list_id]) > >>@mailinglist_mailings = @mailinglist.mailings.collect > > This line above is pointless. collect with no block passed just > returns the original array. > THe point of collect/map is to create a new collection by applying a > function to each element (eg given an array of numbers construct an > array with the square of each number: numbers.collect {|n| n*n} ) > > @mailing_list.mailings.each do |mailing| > Emailer.deliver_contact(mailing.email_address, > @mail_template.subject, @mail_template.body) > end > > > Fred one final question.. i have the code working, and can send a mail template to a list of mailings... but in order to send more than one mailtemplate to these users i have had to create a button for each template as shown below.. <% for mail_template in @mailinglist_templates %> <%= button_to "sendmail", { :action => "send_mail", :mail_template_id => mail_template.id, :id => params[:id] } %> <% end %> now this i know is poor programming and looks bad too.. is there a way i can just have one button that sends each of the mail templates to all the users in the list..? again many thanks for your help!! -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On 2 Dec 2008, at 13:26, Dave Smith wrote: > >>>>> Fred >>> button_to :send_mail, :id => some_template.id, :mailing_list_id => >>> end >> mailings (database table shown below). >>@mail_template = MailTemplate.find(params[:id]) >>@mailing_list = MailingList.find(params[:mailing_list_id]) > >>@mailinglist_mailings = @mailinglist.mailings.collect > > This line above is pointless. collect with no block passed just > returns the original array. > THe point of collect/map is to create a new collection by applying a > function to each element (eg given an array of numbers construct an > array with the square of each number: numbers.collect {|n| n*n} ) > > @mailing_list.mailings.each do |mailing| > Emailer.deliver_contact(mailing.email_address, > @mail_template.subject, @mail_template.body) > end > > > Fred yep brilliant, a few tweaks here and there and ive got it running. Thank you very much for your help! Kindest Regrds -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On 2 Dec 2008, at 11:27, Dave Smith wrote: > >>>>> @mailinglist_mailings = @mailinglist.mailings.collect >>> I think AJAX is an orthogonal issue - you could have a regular button >>> or an ajax one and it wouldn't change much. >>> >>> >>> Fred >> >> to be honest i dont really care how the emails are sent. which ever >> method is easiest to impliment. Do you know of any examples that are >> similar as I dont really know where to start on this one. >> > > I'm sort of struggling to see what the problem is to be honest. > > if in your view you had > > button_to :send_mail, :id => some_template.id, :mailing_list_id => > some_mailing_list_id > > then your controller could be as simple as > > def send_mail >@mail_template = MailTemplate.find params[:id] >@mailing_list = MailingList.find params[:mailing_list_id] >@mailing_list.people.each do |person| > Emailer.deliver_message person.email_address, > @mail_template.subject, @mail_template.body >end > end > > (I'm assuming a bunch of things about which attributes and > associations your models have but it should be quite obvious) > > Fred Thank you Fred, It gets a little more complicated because the mailinglist has many mailings (database table shown below). id mailinglist_id name email_address 1 2 Dave Smith [EMAIL PROTECTED] So I thought you would have to collect these first then loop through them... somthing like the following perhaps? def send_mail @mail_template = MailTemplate.find(params[:id]) @mailing_list = MailingList.find(params[:mailing_list_id]) @mailinglist_mailings = @mailinglist.mailings.collect - @mailinglist_mailings.mailing.each do |mailing| Emailer.deliver_contact(mailing.email_address, @mail_template.subject, @mail_template.body) end return if request.xhr? render :text => 'Message sent successfully' end but i dont think that the line @mailinglist_mailings.mailing.each do |mailing| is right -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On 2 Dec 2008, at 10:48, Dave Smith wrote: > >>>>> many relationship). >>>> ? >>>> Fred >>> >>> yeah well in my mailinglist controller I have put >>> >>> @mailinglist_mailings = @mailinglist.mailings.collect >>> >>> so essentially very similar >> >> so does that mean I put an AJAX button in my view page to run the "do" >> code, or does the code have to be placed in the emailer model? > > whether this happens in the controller or in the emailer this mostly > depends if you want 1 email sent to everyone, or to send however many > separate emails (with identical content). > I think AJAX is an orthogonal issue - you could have a regular button > or an ajax one and it wouldn't change much. > > > Fred to be honest i dont really care how the emails are sent. which ever method is easiest to impliment. Do you know of any examples that are similar as I dont really know where to start on this one. Kindest Regards, Dave -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Dave Smith wrote: > Frederick Cheung wrote: >> On 1 Dec 2008, at 16:58, Dave Smith wrote: >> >>> recipient, subject, message to the emailer model. >>> >>> However I created a mailings scaffold which holds each of the email >>> addresses, and names for the people on the mailinglist (with a one to >>> many relationship). >>> >>> So now I am stuck as I dont know how to create a button that sends an >>> email to all the mailings in a mailinglist with the >>> mailinglist_template >>> associated with that mailinglist!! >>> >> Doesn't that just mean that recipients = mailinglist.people.collect {| >> person| person.email_address} >> ? >> Fred > > yeah well in my mailinglist controller I have put > > @mailinglist_mailings = @mailinglist.mailings.collect > > so essentially very similar so does that mean I put an AJAX button in my view page to run the "do" code, or does the code have to be placed in the emailer model? Sorry for my lack of knowledge as ive only been using rails for a couple of weeks and am learning it by myself. -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Frederick Cheung wrote: > On 1 Dec 2008, at 16:58, Dave Smith wrote: > >> recipient, subject, message to the emailer model. >> >> However I created a mailings scaffold which holds each of the email >> addresses, and names for the people on the mailinglist (with a one to >> many relationship). >> >> So now I am stuck as I dont know how to create a button that sends an >> email to all the mailings in a mailinglist with the >> mailinglist_template >> associated with that mailinglist!! >> > Doesn't that just mean that recipients = mailinglist.people.collect {| > person| person.email_address} > ? > Fred yeah well in my mailinglist controller I have put @mailinglist_mailings = @mailinglist.mailings.collect so essentially very similar -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Re: Sending mail templates to a mailinglist
Hi Fred, At present the recipient is a single email address coming from the emailer page (just to test the mailer works). I have moved the sendmail form into the mailinglists index view page (and also moved the sendmail function from the emailer controller to the mailinglist controller) and it still works fine by sending the recipient, subject, message to the emailer model. However I created a mailings scaffold which holds each of the email addresses, and names for the people on the mailinglist (with a one to many relationship). So now I am stuck as I dont know how to create a button that sends an email to all the mailings in a mailinglist with the mailinglist_template associated with that mailinglist!! Any help on this would be greatly appreciated!! Kindest Regards, Louis Frederick Cheung wrote: > On 1 Dec 2008, at 10:54, Dave Smith wrote: > >> >> >> As a noob to rails I am struggling with being able to send a mail >> template (html) stored in my database to all the users on a mailing >> list. I can use the emailer page to send the mail template to a single >> email address, but I want to be able to put a button on the >> mailinglists >> show page that sends the mail template to all the mailings in the >> mailinglist. The code is below for the key sections I am using. >> > > Well instead of doing > > Emailer.deliver_contact(recipient, subject, message) > > You could clearly do > > recipients.each do |recipient| >Emailer.deliver_contact(recipient, subject, message) > end > > assuming that recipients was some collection of email addresses > > Fred -- 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@googlegroups.com 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 -~--~~~~--~~--~--~---
[Rails] Sending mail templates to a mailinglist
As a noob to rails I am struggling with being able to send a mail template (html) stored in my database to all the users on a mailing list. I can use the emailer page to send the mail template to a single email address, but I want to be able to put a button on the mailinglists show page that sends the mail template to all the mailings in the mailinglist. The code is below for the key sections I am using. I have been trying to figure out a solution for 4 days now and still cannot get anything working and am loosing the will to live!! Please if anyone could help me on this one I would be very very greatfull. Regards, David emailer controller --- class Admin::EmailerController < Admin::AdminController def sendmail email = params[:email] recipient = email["recipient"] subject = email["subject"] message = email["message"] Emailer.deliver_contact(recipient, subject, message) return if request.xhr? render :text => 'Message sent successfully' end #def index # render :file => 'app\views\admin\emailer\index.html.erb' #end end -- emailer index.html.erb --- Send Email <% form_tag :action => "sendmail" do %> Subject: <%= text_field 'email', 'subject' %> Recipient: <%= text_field 'email', 'recipient' %> Message <%= text_area 'email', 'message' %> <%= submit_tag "sendmail" %> <% end %> - mailinglists show.html.erb - using the mail_template - Mail Template(s) in use: <% for mail_template in @mailinglist_templates %> <%= link_to "#{mail_template.name}", admin_mail_template_path(mail_template), :class => 'websnapr' %> <%= link_to 'Edit', edit_admin_mail_template_path(mail_template) %> <% end %> Subscriber List <% for mailing in @mailinglist_mailings %> <%= mailing.email_address %> <% end %> -- oh and here is my mailer model class Admin::Emailer < ActionMailer::Base def contact(recipient, subject, message, sent_at = Time.now) @subject = subject @recipients = recipient @from = '[EMAIL PROTECTED]' @sent_on = sent_at @content_type = "text/html" @body["title"] = 'This is title' @body["email"] = '[EMAIL PROTECTED]' @body["message"] = message @headers = {} 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@googlegroups.com 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 -~--~~~~--~~--~--~---