Search Results

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

Page 90/378 | < Previous Page | 86 87 88 89 90 91 92 93 94 95 96 97  | Next Page >

  • Ruby on Rails 2.3.5: update_all failing on ActiveRecord

    - by randombits
    I'm trying to update a collection of records in my database using ActiveRecord's update_all. Enter script/console. MyModel.update_all("reserved = 1", :order => 'rand()', :limit => 1000) ActiveRecord thinks order is a column, says it's unknown and throws an exception. According to the documentation though, my syntax looks sane. This is RoR 2.3.5. When doing MyModel.update_all("reserved = 1") alone, it works just fine. Also if I do MyModel.update_all("reserved = 1", "reserve_type = 2", :order = "rand()", :limit = 1000) = 0 0 rows affected. I'm simply trying to do: UPDATE MyModel SET reserved=1, reserve_type=2 ORDER BY RAND() LIMIT 1000

    Read the article

  • Rails 3, changing a specific value in a row

    - by Elliot
    Hey Guys, This question seems ridiculously easy, but I seem to be stuck. Lets say we have a table "Books" Each Book, has a name, description, and a status. Lets say I want to create link in the show view, that when clicked, solely changes the status (to "read") for example. So far, I've tried adding a block in the controller, that says: def read @book = Book.find(params[:id]) @book.status = "Read" @book.update_attributes(params[:book]) respond_to do |format| format.html { redirect_to :back} format.xml { render :xml => @book } end end Then I've added a link to the view that is like: <%= link_to "Read", read_book_path(@book), :method = :put % This isn't working at all. I have added it to my routes, but it doesn't seem to matter. Any help would be great! Thanks! -Elliot EDIT: Forgot to add I'm getting a NoMethodError: undefined method `read_book_path'

    Read the article

  • Odd Drag and drop sorting error Rails for nested attributes

    - by Senthil
    I've got this weird bug when trying to use drag and drag for two models (one nested within another). I've a category model which has many apps. In my category index page, I tried use "content_tag_for" to sort categories and apps within each category. But for some odd reason only the first element has drag, drop enabled. I can drag and drop categories all I want, but I can't drag the app in the second category, just the first category. Copy and paste gets ridiculously hopeless with HAML, so here's a Pastie instead. I made a sample app on heroku for you to check out here. Drag and drag work for both category and app, so I'm guessing it has to do something with the ul or li. Any help is appreciated. Thanks.

    Read the article

  • Ruby/Rails Audio Conversion Plugins?

    - by coneybeare
    I am looking for a good gem/plugin to convert user-uploaded audio files to different formats. One format in particular that I am interested in is converting to Apple .caf with ima4 compression for inclusion in an iPhone app. I have been using afconvert on my mac for this so far, but I need to do it on my linux box, server-side. Ideally, I would be able to work into paperclip. As an additional solution, ffmpeg could work, but I have not seen any .caf options for it. Anybody know of one?

    Read the article

  • Adding Table Columns to a Group by clause - Ruby on Rails - Postgresql

    - by bgadoci
    I am trying to use Heroku and apparently Postgresql is a lot more strict than SQL for aggregate functions. When I am pushing to Heroku I am getting an error stating the below. On another question I asked I received some guidance that said I should just add the columns to my group by clause and I am not sure how to do that. See the full error below and the PostsControll#index. SELECT posts.*, count(*) as vote_total FROM "posts" INNER JOIN "votes" ON votes.post_id = posts.id GROUP BY votes.post_id ORDER BY created_at DESC LIMIT 5 OFFSET 0): PostsController def index @tag_counts = Tag.count(:group => :tag_name, :order => 'count_all DESC', :limit => 20) conditions, joins = {}, :votes @ugtag_counts = Ugtag.count(:group => :ugctag_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

    Read the article

  • Rails RJS template displays code instead of the html page

    - by Anand
    After having Googled and hurting my brain for hours on this, I finally decided to post this question. Here's the code... view1.html.erb -------------- <%=link_to_remote_redbox "Link", :url => {:action => :action1, :id => @some.id} some_controller.rb ------------------ def action1 render :layout => false end def action2 do some processing end action1.html.erb -------------------- <form onsubmit="new Ajax.Request('/some_controller/action2', {asynchronous:true, evalScripts:true, onComplete:function(request){RedBox.close(); return false;}, parameters:Form.serialize(this)}); return false;}" method="post" action="/some_controller/action2"> <input type=text name='username'> <input type='submit' value='submit'> </form> action2.rjs ----------- page.replace_html("some_div", (render(:partial => "some_partial"))) with that code in place when action2.rjs kicks in it should display the html page instead I am getting this Element.update("some_div", "<style type=\"text/css\">\n\n.............. As suggested on other posts I read, they say its caused because of the ":update = some_div" in the link_to_remote_redbox function but clearly my code doesn't have that. Help is always appreciated. Many Thanks

    Read the article

  • How to hunt down a long running request in Rails

    - by Jake
    We have a customer complaining about a long running request. I found the request in the production.log but am not sure how to dig deeper into figuring out why it took so long. Is there any artifacts in the log that I should look for? Also the DB and View times don't add up to the total request time.

    Read the article

  • Rails: creating a custom data type / creating a shorthand

    - by Shyam
    Hi, I am wondering how I could create a custom data type to use within the rake migration file. Example: if you would be creating a model, inside the migration file you can add columns. It could look like this: def self.up create_table :products do |t| t.column :name, :string t.timestamps end end I would like to know how to create something like this: t.column :name, :my_custom_data_type The reason for this to create for example a "currency" type, which is nothing more than a decimal with a precision of 8 and a scale of 2. Since I use only MySQL, the solution for this database is sufficient enough. Thank you for your feedback and comments!

    Read the article

  • Fetching email using Ruby on Rails

    - by Shreyas Satish
    I need to fetch email from my gmail account using RoR. require 'net/pop' Net::POP3.start('pop.gmail.com', 995, username, password) do |pop| if pop.mails.empty? puts 'No mail.' else #pop.each_mail do |mail| #p mail.header #p mail.pop puts "Mails present" #end end end I get a timeout error. usr/lib/ruby/1.8/timeout.rb:60:in new': execution expired (Timeout::Error) from /usr/lib/ruby/1.8/net/protocol.rb:206:inold_open' from /usr/lib/ruby/1.8/net/protocol.rb:206:in old_open' from /usr/lib/ruby/1.8/net/pop.rb:438:indo_start' from /usr/lib/ruby/1.8/net/pop.rb:432:in `start' from script/mail.rb:4 Thanks and Cheers !

    Read the article

  • Rails 2.3 - Storing sessions in different schema

    - by sa125
    Hi - I want to config my app to use a different schema than the default for storing sessions. Basically, I want the app to store all its active_record objects in app_development and only its sessions in app_sessions. Normally this could be done by defining the sessions db in database.yml: development: # ... sessions: host: localhost database: app_sessions username: blah password: sssshhh #.... And then setting in the model: class Session < ActiveRecord::Base establish_connection :sessions #... end But since session doesn't have a model class defined, I'm looking for a way to tell it where to store its data. I've noticed the session comes from ActionController::Session, but couldn't find what I needed there. Any thoughts? thanks.

    Read the article

  • dynamic link_to_remote in rails with jquery

    - by Claus Lensbøl
    Hi I'm trying to pass a string with a link_to_remote call as the :id, and the string should be collected from an input field with and id of "movie_title". <div id="search_list">Nothing here yet</div> <br /> <% semantic_form_for @movie do |f| %> <% f.inputs do -%> <%= f.input :title, :class => "movie_title" %> <%= link_to_remote( 'Search...', { :url => { :action => :imdb_search, :id => "'+$('\#movie_title').value+'" } }, { :title => "Search for this movie", :class => "imdb_search" } ) -%> [...removed text that does not matter...] <% end -%> <%= f.buttons %> <% end %> I keep getting an javascript error, and if I remove the # from the jquery in the link, it returns "Undefined". The link I get is: <a class="imdb_search" href="#" onclick="jQuery.ajax({data:'authenticity_token=' + encodeURIComponent('yHPHYTZsPTQLi9JYSauUYcoie/pqPPk2uHBTN0PzNsQ='), dataType:'script', type:'post', url:'/movies/imdb_search/'+$('%23movie_title').value+''}); return false;" title="Search for this movie">Search...</a> So I want the link updated with the contents of movie_title. How do I do that?

    Read the article

  • Testing Rails Metal/Rack with RSpec?

    - by Matt Darby
    Say I have a Metal class named Preview. How do I test it with RSpec? When I try: require 'spec_helper' describe Preview do it "should return the posted content" do post "/preview", :content => "*title*" response.body.should == "*title*" end end I get: undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0x1058b3098> It seems that RSpec doesn't load up the :post method if the test isn't explicitly for a Controller. I've tried specifying :type => :controller to no avail.

    Read the article

  • Testing a scoped find in a Rails controller with RSpec

    - by Joseph DelCioppio
    I've got a controller called SolutionsController whose index action is different depending on the value of params[:user_id]. If its nil, then it simply displays all of the solutions on my site, but if its not nil, then it displays all of the solutions for the given user id. Here it is: def index if(params[:user_id]) @solutions = @user.solutions.find(:all) else @solutions = Solution.find(:all) end end and @user is determined like this: private def load_user if(params[:user_id ]) @user = User.find(params[:user_id]) end end I've got an Rspec test to test the index action if the user is nil: describe "GET index" do context "when user_id is nil" do it "should find all of the solutions" do Solution.should_receive(:find).with(:all).and_return(@solutions) get :index end end end however, can someone tell me how I write a similar test for the other half of my controller, when the user id isn't nil? Something like: describe "GET index" do context "when user_id isn't nil" do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :user => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions).and_return(@solutions) get :index, :user_id => @user.id end end end But that doesn't work. Can someone help me out? Joe

    Read the article

  • Prawn PDF with Rails mailer?

    - by Danny McClelland
    Hi Everyone, I have successfully created an email that sends on creation of a Kase, but now I need to attach a PDF that is created on the fly by Prawn and Prawno. Basically when you visit a kase such as application.com/kase/1 you just append the URL with .pdf i.e. application.com/kase/1. I spent ages getting the PDF to work and look how I wanted, but I can't figure out how to add the PDF to an auto sending email - mainly because I cannot work out how to give it a link as it's auto generated. Has anyone ever managed to get this to work? Thanks, Danny

    Read the article

  • Poor Ruby on Rails performance when using nested :include

    - by Jeremiah Peschka
    I have three models that look something like this: class Bucket < ActiveRecord::Base has_many :entries end class Entry < ActiveRecord::Base belongs_to :submission belongs_to :bucket end class Submission < ActiveRecord::Base has_many :entries belongs_to :user end class User < ActiveRecord::Base has_many :submissions end When I retrieve a collection of entries doing something like: @entries = Entry.find(:all, :conditions => ['entries.bucket_id = ?', @bucket], :include => :submission) The performance is pretty quick although I get a large number of extra queries because the view uses the Submission.user object. However, if I add the user to the :include statement, the performance becomes terrible and it takes over a minute to return a total of 50 entries and submissions spread across 5 users. When I run the associated SQL commands, they complete in well under a second. @entries = Entry.find(:all, :conditions => ['entries.bucket_id = ?', @bucket], :include => {:submission => :user}) Why would this second command have such terrible performance compared to the first?

    Read the article

  • I set up better-edit-in-place but still cannot edit in place in Rails

    - by Angela
    I installed the plugin better-edit-in-place (http://github.com/nakajima/better-edit-in-place) but I dont' seem to be able to make it work. When I use firebug, it is rendering the value to be edited correctly: <span rel="/emails/1" id="email_1_days" class="editable">7</span> And it is showing the full javascript which should work on class editable: var Editable = Class.create({ 5 initialize: function(element, options) { 6 this.element = $(element); 7 Object.extend(this, options); 8 9 // Set default values for options 10 this.editField = this.editField || {}; 11 this.editField.type = this.editField.type || 'input'; 12 this.onLoading = this.onLoading || Prototype.emptyFunction; 13 this.onComplete = this.onComplete || Prototype.emptyFunction; 14 15 this.field = this.parseField(); 16 this.value = this.element.innerHTML; 17 18 this.setupForm(); 19 this.setupBehaviors(); 20 }, 21 22 // In order to parse the field correctly, it's necessary that the element 23 // you want to edit in place for have an id of (model_name)_(id)_(field_name). 24 // For example, if you want to edit the "caption" field in a "Photo" model, 25 // your id should be something like "photo_#{@photo.id}_caption". 26 // If you want to edit the "comment_body" field in a "MemberBlogPost" model, 27 // it would be: "member_blog_post_#{@member_blog_post.id}_comment_body" 28 parseField: function() { 29 var matches = this.element.id.match(/(.*)_\d*_(.*)/); 30 this.modelName = matches[1]; 31 this.fieldName = matches[2]; 32 if (this.editField.foreignKey) this.fieldName += '_id'; 33 return this.modelName + '[' + this.fieldName + ']'; 34 }, But when I point my mouse at the element, no in-place-editing action!

    Read the article

  • Memcached and Rails Fragment Caching Issue

    - by Michael Waxman
    When I have 2 views that fragment cache the same query BUT display them differently, there is only one fragment and they both display it the same way. Is there any way around this? For example... #views/posts/list - cache(@posts) do - for p in @posts = p.title #views/posts/list_with_images - cache(@posts) do - for p in @posts = p.title = p.content = image_tag(p.image_url) #controllers/posts_controller def list ... @posts = Post.all end def list_with_images ... @posts = Post.all end

    Read the article

  • Creating thousands of records in Rails

    - by willCosgrove
    Let me set the stage: My application deals with gift cards. When we create cards they have to have a unique string that the user can use to redeem it with. So when someone orders our gift cards, like a retailer, we need to make a lot of new card objects and store them in the DB. With that in mind, I'm trying to see how quickly I can have my application generate 100,000 Cards. Database expert, I am not, so I need someone to explain this little phenomena: When I create 1000 Cards, it takes 5 seconds. When I create 100,000 cards it should take 500 seconds right? Now I know what you're wanting to see, the card creation method I'm using, because the first assumption would be that it's getting slower because it's checking the uniqueness of a bunch of cards, more as it goes along. But I can show you my rake task desc "Creates cards for a retailer" task :order_cards, [:number_of_cards, :value, :retailer_name] => :environment do |t, args| t = Time.now puts "Searching for retailer" @retailer = Retailer.find_by_name(args[:retailer_name]) puts "Retailer found" puts "Generating codes" value = args[:value].to_i number_of_cards = args[:number_of_cards].to_i codes = [] top_off_codes(codes, number_of_cards) while codes != codes.uniq codes.uniq! top_off_codes(codes, number_of_cards) end stored_codes = Card.all.collect do |c| c.code end while codes != (codes - stored_codes) codes -= stored_codes top_off_codes(codes, number_of_cards) end puts "Codes are unique and generated" puts "Creating bundle" @bundle = @retailer.bundles.create!(:value => value) puts "Bundle created" puts "Creating cards" @bundle.transaction do codes.each do |code| @bundle.cards.create!(:code => code) end end puts "Cards generated in #{Time.now - t}s" end def top_off_codes(codes, intended_number) (intended_number - codes.size).times do codes << ReadableRandom.get(CODE_LENGTH) end end I'm using a gem called readable_random for the unique code. So if you read through all of that code, you'll see that it does all of it's uniqueness testing before it ever starts creating cards. It also writes status updates to the screen while it's running, and it always sits for a while at creating. Meanwhile it flies through the uniqueness tests. So my question to the stackoverflow community is: Why is my database slowing down as I add more cards? Why is this not a linear function in regards to time per card? I'm sure the answer is simple and I'm just a moron who knows nothing about data storage. And if anyone has any suggestions, how would you optimize this method, and how fast do you think you could get it to create 100,000 cards? (When I plotted out my times on a graph and did a quick curve fit to get my line formula, I calculated how long it would take to create 100,000 cards with my current code and it says 5.5 hours. That maybe completely wrong, I'm not sure. But if it stays on the line I curve fitted, it would be right around there.)

    Read the article

  • Rails Routing Broken In Production - Caching of routes.rb suspected

    - by ming yeow
    Hi folks, i have an urgent problem. Essentially, my routing works on my localhost. But when i deployed this to production, the routes does not seem to work correctly. For example, given a new route "/invites" - sometimes i will get a 404, and sometimes it will work correctly. I suspect there is some caching going on somewhere, but i am not sure. Logs: when a page is not found (when the routes are supposed to be accurate) Processing UsersController#network (for 67.180.78.126 at 2010-06-01 09:59:31) [GET] Parameters: {"id"="new"} ActionController::RoutingError (No route matches "/comm/role_playing_games" with {}): app/controllers/application_controller.rb:383:in prev_page_label' app/controllers/application_controller.rb:238:in log_timed_info' app/controllers/users_controller.rb:155:in network' app/controllers/users_controller.rb:151:in network' app/controllers/application_controller.rb:44:in turn_on_query_caching' app/controllers/application_controller.rb:43:in turn_on_query_caching' app/controllers/application_controller.rb:42:in turn_on_query_caching' app/controllers/application_controller.rb:41:in turn_on_query_caching' app/controllers/application_controller.rb:40:in turn_on_query_caching' app/controllers/application_controller.rb:39:in turn_on_query_caching' haml (3.0.6) lib/sass/plugin/rack.rb:41:in `call' Rendering /mnt/app/releases/20100524233313/public/404.html (404 Not Found)

    Read the article

  • Call child's method or cast parent to child in Rails

    - by Brian
    I have some STI structure like following: class Box has_many :part,:class_name = "Part" end class Part def self.dosomething() end end class TypeA<Part def self.dosomething() end end class TypeB<Part def self.dosomething() end end assuming we have some codes like boxtypeA = Box.new. I am wondering if there is a way to make boxtypeA.part.dosomething() to call TypeA's method not Part's or TypeB's. I think basically what we need to do is to convert the part to TypeA, how can we achieve that? Thx in advance!

    Read the article

  • Call child's method or cast parent to child in Rails

    - by Brian
    I have some STI structure like following: class Box has_many :part,:class_name = "Part" end class Part def self.dosomething() end end class TypeA class TypeB assuming we have some codes like boxtypeA = Box.new. I am wondering if there is a way to make boxtypeA.part.dosomething() to call TypeA's method not Part's or TypeB's. I think basically what we need to do is to convert the part to TypeA, how can we achieve that? Thx in advance!

    Read the article

< Previous Page | 86 87 88 89 90 91 92 93 94 95 96 97  | Next Page >