Search Results

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

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

  • Rails: three most recent records by unique belongs_to associated record

    - by Dennis Collective
    class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} named_scope :by_unique_users end what would I put in the :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user on sqlite named_scope :by_unique_user, :group = "user_id" works, but makes it freak out on postgres, which is deployed on production PGError: ERROR: column "comments.id" must appear in the GROUP BY clause or be used in an aggregate function

    Read the article

  • Rails 3 ActiveModel Nested Class I18n

    - by Dave
    Given the following class definition in ruby: class Conversation class Message include ActiveModel::Validations attr_accessor :quantity validates :quantity, :presence => true end end How can you use i18n to customize to error message. For example the correct lookup for the class Conversation would be activemodel: errors: models: conversation: attributes: quantity: blank: "Some custom message" But what is it for the Message class? I tried: activemodel: errors: models: conversation: message: attributes: quantity: blank: "Some custom message" activemodel: errors: models: message: attributes: quantity: blank: "Some custom message" activemodel: errors: models: conversation::message: attributes: quantity: blank: "Some custom message" None of them work Any ideas or is this a bug with ActiveModel or I18n?

    Read the article

  • tag statistics with rails

    - by poseid
    I am using the plugin: http://github.com/karmi/is_taggable How can I perform simple statistics on my tags, e.g. what's the most used tag? which tags are not used, etc.? With SQL I would do something like: select id, count(*) from taggings group by taggable_id; But I am not seeing how to do this with the plugin. Thanks!

    Read the article

  • How to thoroughly clean up a ruby on rails project?

    - by hip10
    Hi, I am very new to ruby on rails. I've installed a complicated ruby on rails project via github clone and bundle install, and I was making minor changes to it until it reaches a point whereby it is not stable anymore, sass was throwing strange exceptions, so did other ruby gems. For a rails project, is there a way to clean up the project (aka, remove any "compiled or cached code") and just run again. My alternative now is to go thru github clone and bundle install again, but that means all of my modified changes have to be reapplied again. What is rails equivalent of "make clean" in Java? Is "rake clean" the answer? Do we need to run any bundle commands?

    Read the article

  • Accessing the params hash for year and month rails and using in helper

    - by Matt
    So I took some php code and turned it into a calendar with a helper to make a simple calendar. I got my data from inside the helper: def calendar_maker a = Time.now b = a.month d = a.year h = Time.gm(d,b,1) #first day of month Now I want to try and do it with parameters within my method #from the helper file def calendar_maker(year, month) a = Time.now b = month c = year h = Time.gm(d,b,1) #first day of month #from my html.erb file <%= @month %> and <%= @year %> <%= params["month"] %><br /> <%= params["action"] %><br /> <%= params["year"] %><br /> <%= calendar_maker( @year, @month) %> #from controller file def calendar @month = params[:month] @year = params[:year] end Anyways mistakes were made and not finding documentation anywhere or not looking in the right place. How do I get this to work with my params hash. Thanks for the help.

    Read the article

  • Not delete params in URL, when sorting [ RAILS 3 ]

    - by kamil
    I have sortable table columns, made like that http://asciicasts.com/episodes/228-sortable-table-columns And I have simply filter options for two columns in table, made at select_tag (GET method). This two function don't work together. When I change filter, the sort parameter disappear and inversely. <th><%= sortable "Id" %></th> <th> Status<br/> <form method="get"> <%= select_tag(:status, options_for_select([['All', 'all']]+@statuses, params[:status]),{:onchange => 'this.form.submit()'}) %> </th> <th><%= sortable "Operation" %></th> <th> Processor<br/> <%= select_tag(:processor, options_for_select([['All', 'all']]+@processor_names, params[:processor]),{:onchange => 'this.form.submit()'}) %> </form> </th>

    Read the article

  • Metaprogramming ActiveRecord Rails

    - by Dimitar Vouldjeff
    Hi, I have the following code in my project`s lib directory module Pasta module ClassMethods def self.has_coordinates self.send :include, InstanceMethods end end module InstanceMethods def coordinates [longitude ||= 43.0, latitude ||= 25.0] end end ActiveRecord::Base.extend ClassMethods end And it should create a class method for ActiveRecord::Base - has_coordinates - which I can "assign" to models... But I receive the error undefined local variable or method 'has_coordinates' Thanks in advance!

    Read the article

  • Rails table inheritance issue

    - by Tristan O'Neil
    I've setup some models in the table inheritance fashion and everything seems to be all fine and dandy. But, when I use a collection select field to select values from one of the models it saves it but it saves the ID of the data and not the actual value of the data. So when I try to display the value on the show view it just shows the corresponding ID and not the actual value. Here is my setup. I'm using formtastic as a side note. View <%= show_field "County", @company.county %> Form <%= f.input :county, :label => 'County', :as => :select, :collection => County.find(:all) %> Base Model class Tag < ActiveRecord::Base before_create :set_type before_update :set_type attr_accessible :type, :name, :category belongs_to :company def set_type self.type = self.category end end Inherited Model class County < Tag end

    Read the article

  • Smart Background Thread Task in Ruby on Rails?

    - by elado
    I need to perform a task every 5 seconds, but only when users are using the application. As for now, I use cron that works every minute and activates a task that repeats itself every 5 seconds with sleeps between, for a minute. However, it works also when the application isn't being used. Is there a gem that will do this kind of thing?

    Read the article

  • [Rails] checkbox to update attribute

    - by Jeff
    [Updated a bit] I have a Task model that has a :completed boolean attribute. If I click on it I want it to execute the 'finish' method. The main problem is that I am displays a series of checkboxes in a list and subsequent checkboxes after the first one are ignored. The method is never called for the given task/checkbox combo. I have this chunk of code in my view: <% current_user.tasks.each do |t|%> <% if t.completed == false %> <%= check_box_tag :completed, true, checked = false %> <%= observe_field :completed, :url => { :controller => 'tasks', :action => :finish , :id => t.id }, :frequency => 0.25, :update => :completed, :with => true %> and my finish method looks like this: def finish @task = Task.find(params[:id]) new = {:completed => true} @task.update_attributes(new) render :update do |page| page.replace_html "taskListing", :partial => 'home/task_listing' end

    Read the article

  • Rails - Preventing users from contributing to website when there score is too low - callback / obser

    - by adam
    A User can add a Sentence directly on my website, via twitter or email. To add a sentence they must have a minimum score. If they don't have the minimum score they cant post the sentence and a warning message is either flashed on the website, sent back to them via twitter or email. So I'm wondering how best to code this check. Im thinking a sentence observer. So far my thoughts are in before_create score_sufficient() - score ok = save - score too low = do not save In the case of too low i need to return some flag so that the calling code can then fire off teh relevant warning. What type of flag should I return? False is too ambiguous as that could refer to validation. I could raise an exception but that doesn't sound right or I could return a symbol? Is this even the right approach? What's the best way to code this?

    Read the article

  • Resource mapping in a Ruby on Rails URL (RESTful API)

    - by randombits
    I'm having a bit of difficulty coming up with the right answer to this, so I will solicit my problem here. I'm working on a RESTFul API. Naturally, I have multiple resources, some of which consist of parent to child relationships, some of which are stand alone resources. Where I'm having a bit of difficulty is figuring out how to make things easier for the folks who will be building clients against my API. The situation is this. Hypothetically I have a 'Street' resource. Each street has multiple homes. So Street :has_many to Homes and Homes :belongs_to Street. If a user wants to request an HTTP GET on a specific home resource, the following should work: http://mymap/streets/5/homes/10 That allows a user to get information for a home with the id 10. Straight forward. My question is, am I breaking the rules of the book by giving the user access to: http://mymap/homes/10 Technically that home resource exists on its own without the street. It makes sense that it exists as its own entity without an encapsulating street, even though business logic says otherwise. What's the best way to handle this?

    Read the article

  • Does a rails production.log store indefinitely?

    - by Trip
    If it doesn't, what's the half-life of it? It it does, where can find that information? On my server I found a few logs for each of my releases. But they only date back a few days. Specifically, I am looking for emails that were sent while my mail server was down two weeks ago.

    Read the article

  • Rails: Different prices for different branches, association depending on two other models combined

    - by Greg Lemond
    I have three models: Service has_many :prices has_many :groups, through: prices Price belongs_to :service belongs_to :group Group has_many :prices I want to have an input field (Simple_Form) for every price. In views/services/_form.html.haml I do: simple_form_for @service do |f| simple_fields_for :groups do |g| simple_fields_for :prices do |p| p.input :price With this setup I only get input fields for already saved prices. How I can get a price field for every group? I tried to do it manually, but it got really nasty and didn't work either. Thanks for any ideas!

    Read the article

  • How to create a session in PHP when there is a session on the same domain in Rails?

    - by Tony
    I have a Rails app on a subdomain - xyz.domain.com, and a PHP app on another subdomain - abc.domain.com When a user is logged into the Rails app, I would like to give them a session so that I can log certain events about that user in the PHP app but in the same database of the Rails app. I would essentially just expose an API that requires authentication. What is the best way to go about this? I am not storing the session in a database

    Read the article

  • Testing ActionMailer's receive method (Rails)

    - by Brian Armstrong
    There is good documentation out there on testing ActionMailer send methods which deliver mail. But I'm unable to figure out how to test a receive method that is used to parse incoming mail. I want to do something like this: require 'test_helper' class ReceiverTest < ActionMailer::TestCase test "parse incoming mail" do email = TMail::Mail.parse(File.open("test/fixtures/emails/example1.txt",'r').read) assert_difference "ProcessedMail.count" do Receiver.receive email end end end But I get the following error on the line which calls Receiver.receive NoMethodError: undefined method `index' for #<TMail::Mail:0x102c4a6f0> /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/stringio.rb:128:in `gets' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:392:in `parse_header' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:139:in `initialize' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/stringio.rb:43:in `open' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/port.rb:340:in `ropen' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:138:in `initialize' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:123:in `new' /Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:123:in `parse' /Library/Ruby/Gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:417:in `receive' Tmail is parsing the test file I have correctly. So that's not it. Thanks!

    Read the article

  • How do I correctly install ambethia/recaptcha with rails 3

    - by TLK
    I have done the following steps: Added to gemfile: gem "recaptcha" Added to config/initializers/recaptcha.rb Recaptcha.configure do |config| config.public_key = 'MyKeyHere' config.private_key = 'MyKeyHere' end Added to view: = raw recaptcha_tags Ran: bundle install ...then restarted server. The result? undefined local variable or method `recaptcha_tags' for #<#<Class:0x1053baaa0>:0x1053b69c8>

    Read the article

  • Ruby on Rails when create method fails, render loses local variables

    - by Jimmy
    Hey guys I have a simple create method with some validations and whenever the create method fails due to validation errors it re-renders the 'new' action. The problem is in my new action/view I have a local variable that is established in the action and passed to a partial to render some related information to what the user is creating. Now when my create action fails and I try to re-render the 'new' action I'm getting the always awesome undefined method `cover' for nil:NilClass error. What is the best way to handle re-establishing my action's local variables on a render instead of redirecting to the action again and the user losing the data they input?

    Read the article

  • Rails partial gets double escaped when using link_to_function

    - by dombesz
    Hi, I have the following code. def add_resume_link(name, form) link_to_function name do |page| html = form.fields_for :resumes, @general_resume.resumes.build, :child_index => 'NEW_RECORD' do |form_parent| render :partial => 'resume_form', :locals=>{:form=>form_parent} end page << "$('resumes').insert({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, id) });" end end And on the resume_form i have somewhere: =add_skill_link("Add Skill", form, "resume_#{id}_skills") and the function looks like: def add_skill_link(name, form, id) link_to_function name do |page| html = form.fields_for :skill_items, @general_resume.skill_items.build, :child_index => 'NEW_RECORD' do |form_parent| render :partial=>'skill_form', :locals=>{:form=>form_parent, :parent=>id} end page << "$('#{id}').insert({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, new Date().getTime()) });" end end So basically i have a javascript code which dinamically adds a piece of html (add_resume) and contains another javascript code which dinamically adds a select box to the page. My problem is that the add_skill_link works fine if i use from the server side, i mean rendering from server side. And gets double escaped when using within the upper described way. I tried to remove the escape_javascript from the add_skill_link bit still not good. Any ideas?

    Read the article

  • Including associations optimization in Rails

    - by Vitaly
    Hey, I'm looking for help with Ruby optimization regarding loading of associations on demand. This is simplified example. I have 3 models: Post, Comment, User. References are: Post has many comments and Comment has reference to User (:author). Now when I go to the post page, I expect to see post body + all comments (and their respective authors names). This requires following 2 queries: select * from Post -- to get post data (1 row) select * from Comment inner join User -- to get comment + usernames (N rows) In the code I have: Post.find(params[:id], :include => { :comments => [:author] } But it doesn't work as expected: as I see in the back end, there're still N+1 hits (some of them are cached though). How can I optimize that?

    Read the article

  • Cache headers in Rails

    - by Dimitar Vouldjeff
    Hi, I`m trying to add cache headers on my static files (.css, .js), but only way I found is with some .htaccess stuff that make the page to throw 500 error. So my question is whether there is easier way to add those headers? Thanks in advance.

    Read the article

  • generating XML in rails

    - by PeterWong
    I created a controller having an action: def gen_books_xml @books = Book.find(:all, :conditions => {:owner_id => 1}) respond_to do |format| format.xml { render :xml => @books.to_xml(:root => "Books", :skip_types=>true) } end end How could I implement the to_xml method in the Book model sa that it can generate the following format? <?xml version="1.0" encoding="UTF-8"?> <Books> <Owner>1</Owner> <Book><title>some title</title></Book> <Book><title>some title</title></Book> <Book><title>some title</title></Book> ... </Books> where there is only 1 Owner element and many Book elements I can only output the Book elements but cannot output the one Owner in the same level of Books. Please HELP!!!

    Read the article

  • 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

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