Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 109/378 | < Previous Page | 105 106 107 108 109 110 111 112 113 114 115 116  | Next Page >

  • Customize the From address in Rails application

    - by palani
    Hi , I have mailer action in my application, the mailer is configured with gmail smtp. The following is my config details under environment.rb file require "smtp_tls" ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.perform_deliveries = true ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.default_charset = "utf-8" ActionMailer::Base.default_content_type = "text/html" ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :domain => 'gmail.com', :user_name => "[email protected]", :password => "password", :authentication => :plain The think i want to implement is, when ever the application generating email the from address shows "[email protected]". Is possible to customize the from address. In different places i want to use different From address instead of "[email protected]" I tried with my mailer model: @from = "#{user.email}" In development server log it shows the customized id correctly. if go my email inbox it shows the from address as "[email protected]" Can any one please guide on this. thanks in advance.

    Read the article

  • Ruby/Rails - Add records to an object with each loop iteration / Object vs Arrays

    - by ChrisWesAllen
    I'm trying to figure out how to add records to an existing object for each iteration of a loop. I'm having a hard time discovering the difference between an object and an array. I have this @events = Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops @events = Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end I'm trying to add a new events to the existing @events object based on the id of whatever the loop variable is. But the ( = ) operator just creates a new instance of the @events object. I tried ( += ) and ( << ) as operators but got the error "You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil" I tried created an array events = [] events << Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops events << Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end But I dont know how to call that arrays attributes within the view With objects I was able do create a loop within the view and call all the attributes of that object as well... <table> <% for event in @events %> <tr> <td><%= link_to event.title, event %></td> <td><%= event.start_date %></td> <td><%= event.price %></td> </tr> <% end %> </table> How could i do this with an array set? So the questions are 1) Whats the difference between arrays and objects? 2) Is there a way to add into the existing object for each iteration? 3) If I use an array, is there a way to call the attributes for each array record within the view?

    Read the article

  • How to refactor this Ruby on Rails code?

    - by yuval
    I want to fetch posts based on their status, so I have this code inside my PostsController index action. It seems to be cluttering the index action, though, and I'm not sure it belongs here. How could I make it more concise and where would I move it in my application so it doesn't clutter up my index action (if that is the correct thing to do)? if params[:status].empty? status = 'active' else status = ['active', 'deleted', 'commented'].include?(params[:status]) ? params[:status] : 'active' end case status when 'active' #active posts are not marked as deleted and have no comments is_deleted = false comments_count_sign = "=" when 'deleted' #deleted posts are marked as deleted and have no comments is_deleted = true comments_count_sign = "=" when 'commented' #commented posts are not marked as deleted and do have comments is_deleted = false comments_count_sign = ">" end @posts = Post.find(:all, :conditions => ["is_deleted = ? and comments_count_sign #{comments_count_sign} 0", is_deleted])

    Read the article

  • Rails: Design Pattern to Store Order of Relations

    - by ChrisInCambo
    Hi, I have four models: Customer, QueueRed, QueueBlue, QueueGreen. The Queue models have a one to many relationship with customers A customer must always be in a queue A customer can only be in one queue at a time A customer can change queues We must be able to find out the customers current position in their respective queue In an object model the queues would just have an array property containing customers, but ActiveRecord doesn't have arrays. In a DB I would probably create some extra tables just to handle the order of the stories in the queue. My question is what it the best way to model the relationship in ActiveRecord? Obviously there are many ways this could be done, but what is the best or the most in line with how ActiveRecord should be used? Cheers, Chris

    Read the article

  • Rails: combining multiple find requests

    - by peppermonkey
    What I want to do is something like this: searchid = 4 while searchid != -1 @a += A.find(searchid) @b = B.find(searchid) searchid = @b.parentid end The problem being the line @a += A.find(searchid) The error being something like NoMethodError: undefined method `+' for # So, how do you combine multiple 'find' requests?

    Read the article

  • Rails Load Data into Application every time a New User is Created

    - by looloobs
    Hi I am trying to figure out the "right" way to do this. In my application every time I create a new user I want to have specific data loaded into an associated table. The associated table is a different preset lists. So a User has many lists and those lists have many items. Some of those Items I want to be loaded when the User is created. I really don't know how to go about doing this but I am guessing something like: create User after_create: create Lists (need already existing data for the list names) after_create List then populate Items table with existing data for these Lists. Should I be using seed data for this? Is that alright for production and if so how exactly would I go about doing that. Any guidance or other recommendations are greatly appreciated.

    Read the article

  • Rails testing: assert render action

    - by deb
    How can I write a test to assert that the action new is rendered? def method ... render :action => :new end I'm looking for something like: assert_equal layout, @response.layout assert_equal format, @request.format I know I can't do @response.action Thanks in advance! Deb

    Read the article

  • JQuery LiveValidations with Rails

    - by Shripad K
    I am using this plugin: http://wiki.github.com/augustl/live-validations/ to check if the form field entered is valid or not. How do i disable the live validation for keypress and instead make it only fire when the submit button is clicked?

    Read the article

  • passing text_field values in ajx on rails

    - by user163352
    I'm using <%= text_field 'person', 'one',:id => 'test', :onchange=>remote_function(:url=>{:action=>"update"}, :update=>"test") %> <div id="test"></div> Now I just want to send the value of text_field with :action i.e :url=>{:action=>"update(value_of_text_field_entered"} Don't want to use params[:person][:one]. Any suggestions?or how can I use <%= observe_field % to send the value with action?

    Read the article

  • writing a meta refresh method for rails

    - by aaronstacy
    I want a method in app/controllers/application.rb that can prepend/append text to whatever template gets rendered. Of course I can't call render twice w/o getting a double render error, so is this possible? I want to redirect after a delay using a meta refresh. Here's what I've got: app/controllers/application_controller.rb: def redirect_after_delay (url, delay) @redirect_delay = delay @redirect_url = url render end app/views/layouts/application.html.erb <!DOCTYPE html> <html lang="en"> <head> <%= yield :refresh_tag %> </head> <body> <%= yield %> </body> </html> So then if I want to add a redirect-after-delay, I add the following to 1) my controller and 2) the action's view: app/controllers/my_controller.rb def my_action redirect_after_delay 'http://www.google.com', 3 if some_condition end app/views/my_controller/my_action.html.erb <% content_for :refresh_tag do %> <meta http-equiv='refresh' content='<%=@redirect_delay%>;url=<%=@redirect_url%>'> <% end %> <h1>Please wait while you are redirected...</h1> Since the content_for block never changes, is it possible to do this in some generic way so that I don't have to put <%= yield :refresh_tag %> in each template? (e.g. could redirect_after_delay add it into whatever template is going to be rendered?)

    Read the article

  • Why is Rails date comparison not working?

    - by revgum
    What am I missing here, it's driving me crazy.. >> user.current_login_at.utc > 24.hours.ago.utc => false >> 24.hours.ago.utc => Mon May 17 18:46:16 UTC 2010 >> user.current_login_at.utc => Mon May 17 15:47:44 UTC 2010 user.current_login_at was 27 hours ago, yet the greater than comparison says it was not greater than 24 hours ago. It leaves me scratching my head..

    Read the article

  • Is there a better acts_as_commentable for Rails?

    - by levi rosol
    Here's what I'm looking to do. I have a site where I want the user to be able to leave comments on various Models. acts_as_commentable is the obvious starting point for this, but I'm curious if there is a gem / plug-in with a more robust feature-set. For example: Pre-built partial(s) (w/ or w/o Twitter / FB buttons) Partial(s) that utilize jQuery Twitter and / or FB tunnels (push to the users twitter / FB when they comment) Pre-built mechanism for pushing other users comments to users viewing that Model I can see how some of this functionality could be app specific, however, a generic implementation seems like it would be useful. I'm curious if something like this exists or not.

    Read the article

  • Rails 4 json return on API

    - by El - Key
    I'm creating an API on my application. I currently overrided the as_json method in my model in order to be able to get attached files as well as logo from Paperclip : def as_json( options = {} ) super.merge(logo_small: self.logo.url(:small), logo_large: self.logo.url(:large), taxe: self.taxe, attachments: self.attachments) end Then within my controller, I'm doing : def index @products = current_user.products respond_with @products end def show respond_with @product end The problem is that on the index, I don't want get all the attachments. I only need it on the show method. So I tried it : def index @products = current_user.products respond_with @products, except: [:attachments] end But unfortunately it's not working. How can I do to not send :attachments? Thanks

    Read the article

  • Get SEO friendly URLS with Rails without mehtod_missing?

    - by tesmar
    Hi all, Currently we are using method_missing to catch for calls to SEO friendly actions in our controllers rather than creating actions for every conceivable value for a variable. What we want are URLS like this: /students/BobSmith and NOT /students/show/342 IS there a cleaner solution than method_missing? Thank you!

    Read the article

  • Rails populate edit form for non-column attributes

    - by Rabbott
    I have the following form: <% form_for(@account, :url => admin_accounts_path) do |f| %> <%= f.error_messages %> <%= render :partial => 'form', :locals => {:f => f} %> <h2>Account Details</h2> <% f.fields_for :customer do |customer_fields| %> <p> <%= customer_fields.label :company %><br /> <%= customer_fields.text_field :company %> </p> <p> <%= customer_fields.label :first_name %><br /> <%= customer_fields.text_field :first_name %> </p> <p> <%= customer_fields.label :last_name %><br /> <%= customer_fields.text_field :last_name %> </p> <p> <%= customer_fields.label :phone %><br /> <%= customer_fields.text_field :phone %> </p> <% end %> <p> <%= f.submit 'Create' %> </p> <% end %> As well as attr_accessor :customer And I have a before_create method for the account model which does not store the customer_fields, but instead uses them to submit data to an API.. The only thing I store are in the form partial.. The problem I'm running into is that when a validation error gets thrown, the page renders the new action (expected) but none of the non-column attributes within the Account Detail form will show? Any ideas as to how I can change this code around a bit to make this work me?? This same solution may be the help I need for the edit form, I have a getter for the data which it asks the API for, but without place a :value = "asdf" within each text box, it doesn't populate the fields either..

    Read the article

  • Render as html from a remote link on Rails

    - by francordie
    On my registration form i want to show a modal (of twitter-bootstrap) when the user has a successfull signup to tell him to check his email so i put "remote: true" on my form and render a .js.erb wich shows the modal, on my controller. BUT, in case of inputs errors i need to render the page as html to refresh de form showing those errors. Can I call the controller from the remote form as JS but render as html? (or any other idea to do what i want) Thanks!

    Read the article

  • Rails and date: get profiles with related ages

    - by Totty
    Hy, I have a profile x, that has a born_date and then i want to get all the profiles that has more or less 5 years. If profile x has 20 years, i want every profile that has between 15 and 25 years. Here i need some date calculations and i dont really know how to do it. You have some ideas? ;)

    Read the article

  • Ruby on Rails: Uploading a modifed site.

    - by Califer
    I'm having a heck of a time getting a site I modified to work correctly. I didn't set the site up originally, and since the person that set it up no longer works with me I had to learn ruby just to make some changes. I made all the changes in the development server and everything worked fine. Then I did a diff on the production and development and moved only my changes over. Unfortunately when I loaded my changes onto the production server I got a lot of errors. I've changed all of the permissions to 755, which took care being able to access anything at all, but after that I started getting a lot of 500 errors. Nothing showed up in the production.log file. I really have no clue what's going wrong except that perhaps things are not noticing the new changes. I moved the old site to a backup folder, and the new site crashes whenever it goes to anything that I've changed. In particular, I added a link to a new setup with an extra controller/model/view group. It works fine on development but in production it gives me a 404. Yes, I did copy all the files up. I even put everything back how it was, but the website is still showing the broken version of it. I checked the tmp/cache folder but it was empty. Running dispatch.fcgi shows the old site (which I expected) but it still shows the flawed new site when I connect through a browser. I've been tearing my hair out trying to get this to work. Any ideas as to how I can get this to work?

    Read the article

  • Rails - undefined method `name' for nil:NilClass

    - by sscirrus
    Hi guys, Quick question. Here is my code: #routes map.resources :customers, :has_many => [:addresses, :matchings] map.connect ":controller/:action/:id" #url path: http://127.0.0.1:3000/customers/index/3 #customers controller def index @customer = Customer.find(params[:id]) end #customers view/index.html.erb ... <%= @customer.name %> ... Error: undefined method `name' for nil:NilClass. Here's my reasoning. The parameter :id is coming from my url path (i.e. we're looking for customer #3 in the above path). @customer should find that array easily, then @customer.name should produce the name, but apparently @customer is blank. Why? I assume the problem is that I'm not producing an array in my controller?

    Read the article

  • Generating report with MySQL and Rails - how?

    - by Arywista
    Here is my data model from my application: id :integer(4) not null, primary key spam :boolean(1) not null duplicate :boolean(1) not null ignore :boolean(1) not null brand_id :integer(4) not null attitude :string not null posted_at :datetime not null Attitude could have 3 states: negative, positive, neutral. I want to generate resultset in table, this way, for each day between start and end date: date | total | positive | neutral | negative 2009-10-10 | 12 | 4 | 7 | 1 (...) 2009-10-30 | 5 | 2 | 1 | 1 And ignore all records which have: duplicate = true ignore = true spam = true How it's could be done?

    Read the article

  • Ruby on Rails: restrict file type with Paperclip using a flash uploader

    - by aperture
    I have a pretty basic Paperclip Upload model that is attached to a User model through has_many, and am using Uploadify to do the actual uploading. Flash sends all files with the content type of "application/octet-stream" so using validates_attachment_content_type rejects all files. In my create action, I am able to get the mime-type from the original file name, but only after it's been saved, with: def coerce(params) h = Hash.new h[:upload] = Hash.new h[:upload][:attachment].content_type = MIME::Types.type_for(h[:upload][:attachment].original_filename).to_s ... end and def create diff_params = coerce(params) @upload = Upload.new(diff_params[:upload]) ... end What would be the best way of white listing file types? I am thinking a before_validation method, but I'm not sure how that would work. Any ideas would be welcome.

    Read the article

< Previous Page | 105 106 107 108 109 110 111 112 113 114 115 116  | Next Page >