Search Results

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

Page 86/378 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • Installing Paperclip - "undefined method `has_attached_file` for" - Ruby on Rails

    - by bgadoci
    I just installed the plugin for Paperclip and I am getting an error message "undefined method has_attached_file for. Not sure why I am getting this. Here is the full error message. NoMethodError (undefined method `has_attached_file' for #<Class:0x10338acd0>): /Users/bgadoci/.gem/ruby/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing' app/models/post.rb:2 app/controllers/posts_controller.rb:50:in `show' For some reason it is referencing the will_paginate gem. From what I can find, it seems that either there is something wrong w/ my PostsController#index or perhaps a previously attempt at installing the gem instead of the plugin (in which case I have read I should be able to remedy through the /config/environments.rb file somehow). I didn't think that previous gem installation would matter as I did it in an old version of the site that I trashed before installing the plugin. In the current version of the site I show that the Table has been updated with the Paperclip columns after migration. Here is my code: PostsController#index def index @tag_counts = Tag.count(:group => :tag_name, :order => 'count_all DESC', :limit => 20) conditions, joins = {}, :votes @vote_counts = Vote.count(:group => :post_title, :order => 'count_all DESC', :limit => 20) conditions, joins = {}, :votes unless(params[:tag_name] || "").empty? conditions = ["tags.tag_name = ? ", params[:tag_name]] joins = [:tags, :votes] end @posts=Post.paginate( :select => "posts.*, count(*) as vote_total", :joins => joins, :conditions=> conditions, :group => "votes.post_id", :order => "created_at DESC", :page => params[:page], :per_page => 5) @popular_posts=Post.paginate( :select => "posts.*, count(*) as vote_total", :joins => joins, :conditions=> conditions, :group => "votes.post_id", :order => "vote_total DESC", :page => params[:page], :per_page => 3) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } format.json { render :json => @posts } format.atom end end Post Model class Post < ActiveRecord::Base has_attached_file :photo validates_presence_of :body, :title has_many :comments, :dependent => :destroy has_many :tags, :dependent => :destroy has_many :votes, :dependent => :destroy belongs_to :user after_create :self_vote def self_vote # I am assuming you have a user_id field in `posts` and `votes` table. self.votes.create(:user => self.user) end cattr_reader :per_page @@per_page = 10 end /views/posts/new.html.erb <h1>New post</h1> <%= link_to 'Back', posts_path %> <% form_for(@post, :html => { :multipart => true}) do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.label :body %><br /> <%= f.text_area :body %> </p> <p> <%= f.file_field :photo %> </p> <p> <%= f.submit 'Create' %> </p> <% end %>

    Read the article

  • delayed job problem in rails.

    - by krunal shah
    My controller data_files_controller.rb def upload_balances DataFile.load_balances(params) end My model data_file.rb def self.load_balances(params) # Pull the file out of the http request, write it to file system name = params['Filename'] directory = "public/uploads" errors_table_name = "snapshot_errors" upload_file = File.join(directory, name) File.open(upload_file, "wb") { |f| f.write(params['Filedata'].read) } # Remove the old data from the table Balance.destroy_all ------ more code----- end It's working fine. Now i want to use delayed job with my controller to call my model action like .. My controller data_files_controller.rb def upload_balances DataFile.send_later(:load_balances,params) end Is it possible?? What's the other way to do it? Is it create any problem? With this send_later i am getting this error in column last_error in delayed_job table. uninitialized stream C:/cyncabc/app/models/data_file.rb:12:in read' C:/cyncabc/app/models/data_file.rb:12:inload_balances' C:/cyncabc/app/models/data_file.rb:12:in open' C:/cyncabc/app/models/data_file.rb:12:inload_balances' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/performable_method.rb:35:in send' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/performable_method.rb:35:inperform' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/backend/base.rb:66:in invoke_job' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:120:inrun' c:/ruby/lib/ruby/1.8/timeout.rb:62:in timeout' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:120:inrun' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:10:in realtime' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:119:inrun' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:180:in reserve_and_run_one_job' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:104:inwork_off' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:103:in times' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:103:inwork_off' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:78:in start' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:10:inrealtime' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:77:in start' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:74:inloop' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/worker.rb:74:in start' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:93:inrun' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:72:in run_process' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:215:incall' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:215:in start_proc' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:225:incall' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:225:in start_proc' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:255:instart' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/controller.rb:72:in run' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:188:inrun_proc' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in call' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:incatch_exceptions' c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:187:in run_proc' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:71:inrun_process' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:65:in daemonize' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:63:intimes' c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:63:in `daemonize' script/delayed_job:5 Without send_later it's working fine... Is there any solution?

    Read the article

  • Nesting Ruby on Rails HAML Checkbox in Label Tag

    - by user1279116
    I have the following code which doesn't work: = form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => "well" }) do |f| = f.label :email = f.email_field :email = f.label :password = f.password_field :password - if devise_mapping.rememberable? %p = f.label :remember_me, :class => "checkbox" = f.check_box :remember_me, :class => "checkbox" %div= f.submit "Einloggen" = render :partial => "devise/shared/links" It only works in that way, but I need it in one line and not in wto: %p = f.label :remember_me, :class => "checkbox" = f.check_box :remember_me, :class => "checkbox" Please help! I'm really desprate right now. I just want the checkbox nested in the label for the bootsrap form. I searched google and stackoverflow but found nothing UPDATE: I solved it now like this: - if devise_mapping.rememberable? %p %label.checkbox{ :for => "remember_me" } = f.check_box :remember_me, :class => "checkbox" Remember

    Read the article

  • Email Net::SMTPFatalError when sending email from Rails App

    - by Danny McClelland
    Hi Everyone, I have setup my application to send an email when a new case is created. if @kase.save UserMailer.deliver_contact_confirmation(@user) I have added the following to my user_mailer.rb def contact_confirmation(user) @subject = 'Message Subject' @body = "Message content" @from = "[email protected]" end but...when I create a new case and click submit I get the following: Net::SMTPFatalError in KasesController#create 555 5.5.2 Syntax error. x1sm110877wbx.1 I have added the SMTP details to the environment.rb as follows: ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :enable_starttls_auto => true, :address => "smtp.gmail.com", :port => "587", :domain => "XXXX.co.uk", :authentication => :plain, :user_name => "[email protected]", :password => "XXXX" } Any ideas? Thanks, Danny

    Read the article

  • Rails model belongs to model that belongs to model but i want to use another name

    - by Micke
    Hello. This may be a stupid question but im just starting to learn Rail thats why i am asking thsi question. I have one model called "User" which handles all the users in my community. Now i want to add a guestbook to every user. So i created a model called "user_guestbook" and inserted this into the new model: belongs_to :user and this into the user model: has_one :user_guestbook, :as => :guestbook The next thing i did was to add a new model to handle the posts inside the guestbook. I named it "guestbook_posts" and added this code into the new model: belongs_to :user_guestbook And this into the user_guestbook model: has_many :guestbook_posts, :as => :posts What i wanted to achive was to be able to fetch all the posts to a certain user by: @user = User.find(1) puts @user.guestbook.posts But it doesnt work for me. I dont know what i am doing wrong and if there is any easier way to do this please tell me so. Just to note, i have created some migrations for it to as follows: create_user_guestbook: t.integer :user_id create_guestbook_posts: t.integer :guestbook_id t.integer :from_user t.string :post Thanks in advance!

    Read the article

  • XML Serialization is not including milliseconds in datetime field from Rails model

    - by revgum
    By default, the datetime field from the database is being converted and stripping off the milliseconds: some_datetime = "2009-11-11T02:19:36Z" attribute_before_type_cast('some_datetime') = "2009-11-11 02:19:36.145" If I try to overrride the accessor for this attribute like; def some_datetime attribute_before_type_cast('some_datetime') end when I try "to_xml" for that model, I get the following error: NoMethodError (undefined method `xmlschema' for "2009-11-11 02:19:36.145":String): I have tried to parse the String to a Time object but can't get one to include the milliseconds; def some_datetime Time.parse(attribute_before_type_cast('some_datetime').sub(/\s/,"T").sub(/$/,"Z")) end Can anyone help get get a datetime with milliseconds rendered by to_xml?

    Read the article

  • Rails 3 / Bundler gem: 'undefined method `setup' for Bundler:Module (NoMethodError)'

    - by ashleyw
    It can be traced back to config/boot.rb, line 7: require 'rubygems' require 'bundler' Bundler.setup This is with Bundler 0.8.1 supposedly installed: ../Users/ashley$ sudo gem install bundler Successfully installed bundler-0.8.1 1 gem installed Installing ri documentation for bundler-0.8.1... Installing RDoc documentation for bundler-0.8.1... Everything I've done has followed this guide. Anyone have any clue what's wrong? Thanks :)

    Read the article

  • Refinery CMS (Rails): Creating a plugin or plugins with multiple models and relationships

    - by jklina
    My goal is to create a way for an admin to create two models in the Refinery admin: Campaigns and Videos I would like to have it setup so that a Campaign has many Videos and that each Video belongs to a Campaign. Both Videos and Campaigns will have a title, description, and a preview image. I'm not certain of the best way to go about this. Is it possible to setup two plugins and form a relationship between the two? Or, should I create one plugin with both models. If someone could point me in the right direction or a good example of a solution to a similar problem, I would be grateful. Thank you for looking!

    Read the article

  • Rails ActiveRecord - Best way to perform an include?

    - by dwhite
    I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through => :collections end class User < ActiveRecord::Base has_many :collections has_many :books, :through => :collections end class Collection < ActiveRecord::Base belongs_to :book belongs_to :user end I'm trying to display a list of the books and have a link to either add or remove from the user's collection. I can't quite figure out the best syntax to do this. For example, if I do the following: Controller class BooksController < ApplicationController def index @books = Book.all end end View ... <% if book.users.include?(current_user) %> ... or obviously the inverse... ... <% if current_user.books.include?(book) %> ... Then queries are sent for each book to check on that include? which is wasteful. I was thinking of adding the users or collections to the :include on the Book.all, but I'm not sure this is the best way. Effectively all I need is the book object and just a boolean column of whether or not the current user has the book in their collection, but I'm not sure how to forumlate the query in order to do that. Thanks in advance for your help. -Damien

    Read the article

  • Sorting deeply nested attributes in Rails

    - by Senthil
    I want to be able to drag and drag App model which is nested under Category model. http://railscasts.com/episodes/196-nested-model-form-part-1 's the Railscast I've tried to follow. Category controller def move params[:apps].each_with_index do |id, index| Category.last.apps.update(['position=?', index+1], ['id=?', Category.last.id]) end render :nothing => true end I'm able to sort Categories with something similar, but since I'm updating an attribute, I'm having trouble. def sort params[:categories].each_with_index do |id, index| Category.update_all(['position=?', index+1], ['id=?', id]) end render :nothing => true end Any help is appreciated.

    Read the article

  • rails paperclip and passenger `is not recognized by the 'identify' command`

    - by Joseph Silvashy
    When I upload a photo, my model fails validation, err well even without any validations I'm returned this error: /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. and /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. I'm confident this is not related to ImageMagick because I've removed any image processing from the uploading, also I've tried uploading different mime types, like .txt files and the such. Additionally, I found something that may work. A blog post claims that putting the following in my environment (in this case development.rb) Paperclip.options[:command_path] = "/opt/local/bin"

    Read the article

  • Rails HABTM accepts_nested_attributes_for mapping table

    - by Rabbott
    Currently I have a habtm relationship between a datastream (stream), and a chart. I want to be able to use the 'typical' jquery "add new stream" method to add a new entry into a mapping table that holds the chart_id, and stream_id.. But I think that most examples out there are made to handle a one to many relationship.. The functionality provided here by Ryan Bates is what I'm looking for, But I dont want to use checkboxes, I want to use a select (drop down) to add new items to the mapping table. I need THIS and THIS combined chart.rb class Chart < ActiveRecord::Base has_and_belongs_to_many :streams, :readonly => false, :join_table => 'charts_streams' accepts_nested_attributes_for :streams, :reject_if => lambda { |a| a.values.all?(&:blank?) }, :allow_destroy => true stream.rb class Stream < ActiveRecord::Base has_and_belongs_to_many :charts, :readonly => false, :join_table => 'charts_streams' application.js /* * Method used to add new child form partials */ $('form a.add_child').click(function() { var assoc = $(this).attr('data-association'); var content = $('#' + assoc + '_fields_template').html(); var regexp = new RegExp('new_' + assoc, 'g'); var new_id = new Date().getTime(); var newElements = jQuery(content.replace(regexp, new_id)).hide(); $(this).parent().before(newElements).prev().slideFadeToggle(); return false; }); /* * Method used to remove child form partials */ $('form a.remove_child').live('click', function() { if(confirm('Are you sure?')) { var hidden_field = $(this).prev('input[type=hidden]')[0]; if(hidden_field) { hidden_field.value = '1'; } $(this).parents('.fields').slideFadeToggle(); } return false; }); _form.html.erb <div id="streams"> <h4>Streams</h4> <% form.fields_for :streams do |stream_form| %> <%= render :partial => "stream", :locals => {:f => stream_form} %> <% end %> </div> <p><%= add_child_link 'Add a stream', :streams %></p> <%= new_child_fields_template(form, :streams) %> _stream.html.erb <div class="fields"> <p> <%= f.label :stream_id %><br /> <%= select_tag "chart[stream_ids][]", options_for_select(@streams.map {|s| [s.label, s.id]}, f.object.id) %> </p> <p><%= remove_child_link 'Remove stream', f %></p> </div> This may be overkill and what I am looking to do could be much easier.. Basically when I create a chart I want to be able to add as many streams to it as I want, using the javascript for adding a new entry, and removing an old one... Thanks for the help! This is 'working' but gives me a ActiveRecord::ReadOnlyRecord error when it hits the chart.update_attributes method.. am I adding the the :readonly = false in the wrong spot? Or am I just doing it completely wrong?

    Read the article

  • Rails, searchlogic choose categories with checkboxes

    - by atmorell
    Hello, I am useing searchlogic to search some paintings. Each painting belong to a single category. What I would like to do is add multiple checkboxes to my search form, so that users can mark multiple categories. (joined with or) Is this possible with searchlogic? The query I am looking for is something like this: SELECT * FROM paintings WHERE category LIKE "white" OR category LIKE "red"... f.check_box :category (white) f.check_box :category (black) f.check_box :category (red) f.check_box :category (green) etc.

    Read the article

  • Rails Catch All Route URL Helpers?

    - by viatropos
    If I have a catch-all-route like this: match '*request_path' => "pages#show", :as => :page ...and the pages can be arbitrarily nested, how do I make it so I can use the url helper methods? If I have a page structure like this: /about /about/people /about/story /about/story/in-depth Then I want to be able to write page_path(@page) and get /about/story/in-depth for the hypothetical "In Depth Story" page. But instead I'm just getting /in-depth. If I override Page#to_param, and do something like this: def to_param result = "" if parent result << parent.to_param result << "/" end result << super end ... it returns an encoded string like this: /about%2Fstory%2Fin-depth Is there a way to make this work?

    Read the article

  • heroku corrupted object, git fsck fails in rails

    - by Ryan Max
    Hello. I am trying to push an app to heroku and I am getting the error detailed here. So I am trying to determine the corrupt objects using git fsck -full but it isn't returning anything. Nothing happens: Ryan@Ryan-PC ~ $ git fsck --full Ryan@Ryan-PC But I get the object error when I try to push the object to heroku. Is there anyway I can go about repairing the corrupt repository, or can I just delete it and start over? How do I go about doing this?

    Read the article

  • In Rails, how to speed up machinist tests?

    - by Bryan Shen
    I'm replacing test fixtures with Machinist. But using Machinist to set up test data is very slow, because whenever a test method is run some new data are made by Machinist and saved to database. Is there any way to cache the data in memory so that using Machinist isn't so slow? Thanks, Bryan

    Read the article

  • Voice chat in Rails

    - by Arkid
    I am working on an application which helps group chat amongst users in a chat room. We are using the Juggernaut plugin for the purpose. I wanted to know whether we should use something else as we need to allow voice audio chat in the next iteration..

    Read the article

  • Getting ActiveRecord (Rails) to_xml to use xsi:nil and xsi:type instead of nil and type

    - by nbeyer
    The default behavior of XML serialization (to_xml) for ActiveRecord objects will emit 'type' and 'nil' attributes that are similar to XML Schema Instance attributes, but aren't set in a XML Namespace. For example, a model might produce an output like this: <user> <username nil="true" /> <first-name type="string">Name</first-name> </user> Is there anyway to get to_xml to utilize the XML Schema Instance namespace and prefix the attributes and the values? Using the above example, I'd like to produce the following: <user xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xs="http://www.w3.org/1999/XMLSchema"> <username xsi:nil="true" /> <first-name xsi:type="xs:string">Name</first-name> </user>

    Read the article

  • Rails: foreign_key that is set with a CASE WHEN mysql statement

    - by user305270
    belongs_to :removed_friend, :class_name => 'Profile', :foreign_key => "(CASE WHEN friendships.profile_id = #{self.id} THEN friendships.friend_id ELSE friendships.profile_id END)" The self.id its not working too :s it should be the id of the profile that is triggered the action. Anyway the main problem is that this foreign_key is not working and i got a mysql error. please help.. thanks

    Read the article

  • Eager-loading association count with Arel (Rails 3)

    - by Matchu
    Simple task: given that an article has many comments, be able to display in a long list of articles how many comments each article has. I'm trying to work out how to preload this data with Arel. The "Complex Aggregations" section of the README file seems to discuss that type of situation, but it doesn't exactly offer sample code, nor does it offer a way to do it in two queries instead of one joined query, which is worse for performance. Given the following: class Article has_many :comments end class Comment belongs_to :article end How can I preload for an article set how many comments each has?

    Read the article

  • Rails Associations - Callback Sequence/Magic

    - by satynos
    Taking following association declaration as an example: class Post has_many :comments end Just by declaring the has_many :comments, ActiveRecord adds several methods of which I am particularly interested in comments which returns array of comments. I browsed through the code and following seems to be the callback sequence: def has_many(association_id, options = {}, &extension) reflection = create_has_many_reflection(association_id, options, &extension) configure_dependency_for_has_many(reflection) add_association_callbacks(reflection.name, reflection.options) if options[:through] collection_accessor_methods(reflection, HasManyThroughAssociation) else collection_accessor_methods(reflection, HasManyAssociation) end end def collection_accessor_methods(reflection, association_proxy_class, writer = true) collection_reader_method(reflection, association_proxy_class) if writer define_method("#{reflection.name}=") do |new_value| # Loads proxy class instance (defined in collection_reader_method) if not already loaded association = send(reflection.name) association.replace(new_value) association end define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value| ids = (new_value || []).reject { |nid| nid.blank? } send("#{reflection.name}=", reflection.class_name.constantize.find(ids)) end end end def collection_reader_method(reflection, association_proxy_class) define_method(reflection.name) do |*params| force_reload = params.first unless params.empty? association = association_instance_get(reflection.name) unless association association = association_proxy_class.new(self, reflection) association_instance_set(reflection.name, association) end association.reload if force_reload association end define_method("#{reflection.name.to_s.singularize}_ids") do if send(reflection.name).loaded? || reflection.options[:finder_sql] send(reflection.name).map(&:id) else send(reflection.name).all(:select => "#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").map(&:id) end end end In this sequence of callbacks, where exactly is the actual SQL being executed for retrieving the comments when I do @post.comments ?

    Read the article

  • Remove all html tags from attributes in rails

    - by Hock
    I have a Project model and it has some text attributes, one is summary. I have some projects that have html tags in the summary and I want to convert that to plain text. I have this method that has a regex that will remove all html tags. def strip_html_comments_on_data self.attributes.each{|key,value| value.to_s.gsub!(/(<[^>]+>|&nbsp;|\r|\n)/,"")} end I also have a before_save filter before_save :strip_html_comments_on_data The problem is that the html tags are still there after saving the project. What am I missing? And, is there a really easy way to have that method called in all the models? Thanks, Nicolás Hock Isaza

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >