Search Results

Search found 297 results on 12 pages for 'rails3'.

Page 8/12 | < Previous Page | 4 5 6 7 8 9 10 11 12  | Next Page >

  • Newbie question: undefined local variable or method , why??

    - by Mellon
    I am new in Rails (I am using Rails 3.0.3), currently I am following the book "Agile Web Development with Rails" to develop a simple rails application. I followed the book to: --create a model 'Cart' class; --implement 'add_to_cart' method in my 'store_controller', I have a line of code <%=button_to "Add to Cart", :action => add_to_cart, :id => product %> in my /store/index.html.erb As you see, there is :action => add_to_cart in my index.html.erb, which will invoke the add_to_cart method in my *Controllers/store_controller.rb* But after I refresh the browser, I got the error "undefined local variable or method 'add_to_cart'", apparently I do have the method add_to_cart in my 'store_controller.rb', why I got this error??? What is the possible cause??? Here are my codes: store_controller.rb class StoreController < ApplicationController def index @products = Product.find_products_for_sale end def add_to_cart product = Product.find(params[:id]) @cart = find_cart @cart.add_product(product) end private def find_cart session[:cart] ||= Cart.new end end /store/index.html.erb <h1>Your Pragmatic Catalog</h1> <% @products.each do |product| -%> <div class="entry"> <%= image_tag(product.image_url) %> <h3><%=h product.title %></h3> <%= product.description %> <div class="price-line"> <span class="price"><%= number_to_currency(product.price) %></span> <!-- START_HIGHLIGHT --> <!-- START:add_to_cart --> **<%= button_to 'Add to Cart', :action => 'add_to_cart', :id => product %>** <!-- END:add_to_cart --> <!-- END_HIGHLIGHT --> </div> </div> <% end %> Model/cart.rb class Cart attr_reader :items def initialize @items = [] end def add_product(product) @items << product end end

    Read the article

  • Why do i get a circular reference exception when calling to_json on an ActiveRecord::Relation

    - by midas06
    In Rails 3 (beta 3 on 1.8.7), when calling to_json on a relation i get a circular reference exception. Converting that relation to an array first, and THEN calling to_json works. Code That fails: Model.where().to_json (Where model is any model in your Rails 3 app) Code that works: Model.where().to_a.to_json This can be reproed on the console. Has anyone else run in to this? Is this expected?

    Read the article

  • Trying to Install Rails 3

    - by Rob Fuller
    I'm trying to install Rails 3 on a brand new MacBook Pro running OS X 10.6.3, Ruby 1.8.7, and Rails 2.3.5 and I'm wondering if I've hosed myself. So far, I've run these commands: $ gem update --system $ gem install arel tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n $ gem install rails --pre However, when I run the last command, I get this error: ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /usr/bin directory. I think it wants me to run the command with sudo so that it can write over /usr/bin/rails. But if I do that, won't I be overwriting my Rails 2.3.5 executable? I don't want to do that. Instead, I'd like to keep both versions of Rails. Can anyone help? Thanks.

    Read the article

  • Problems installing RMagick with Paperclip in Rails 3

    - by Smickie
    Hi, I'm trying to use paperclip in rails and when I'm doing the "bundle install" I'm getting the following error: Can't install RMagick 2.13.1. Can't find Magick-config in /usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/seanhinton/.rvm/bin What I'm wondering is how do I install RMagick (is that what I need?) on my machine (it's OSX 10.6)? Cheers!

    Read the article

  • Problem w/ Paperclip, MacPorts, ImageMagick & Snow Leopard

    - by Kyle Decot
    I'm attempting to use ImageMagick along w/ Paperclip to handle the images on my rails app. The problem is whenever I try to upload an image I get the following in the terminal: [paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /var/folders/go/goZ833AaFaqyvv5RnLqQmE+++TM/-Tmp-/stream20110107-6356-1xfs9j1-0.jpg is not recognized by the 'identify' command.> I have added the following to my environments/development.rb file: Paperclip.options[:command_path] = "/usr/local/bin" If I try to interact w/ ImageMagick in the terminal by using "convert" or something similar I get: dyld: Library not loaded: /opt/local/lib/libltdl.7.dylib Referenced from: /usr/local/bin/convert Reason: Incompatible library version: convert requires version 10.0.0 or later, but libltdl.7.dylib provides version 9.0.0 Trace/BPT trap I've already tried updating everything w/ port but the problem still persists. Does anyone have any ideas or suggestions?

    Read the article

  • uninitialized constant OpenSSL::Digest::SHA1 in rails 3 and ubuntu

    - by Anand Agrawal
    Hi All, I am trying to integrate restful_authentication plugings into my rails 3 application. I integrated this in windows, but while trying to integrate it to ubuntu I am facing an error "uninitialized constant OpenSSL::Digest::SHA1" I googled for the solution but still unsuccessful. I am unable to load the file, "require Digest/SHA1" Now, i tried to run console screen. and tried to check the Digest file by putting print statement, this gives false, while in the irb it returns true. If anyone has come across such problem

    Read the article

  • Create an own "OpenID-like system" Provider

    - by user502052
    I know that Facebook use their own OpenID-like system called "Facebook connect", which you can use to authenticate users on your site, among other features. In my case I have multiple Ruby on Rails applications: users.example.com profiles.example.com photos.example.com ... I would like to use 'users.example.com' as a web service that allows users to authenticate to all my other applications the same way as works "Facebook connect" or OpenID. In few words, 'users.example.com' must works as a "OpenID-like system" for my applications in 'example.com'. Can anyone give me tips and links to some useful resources? P.S.: since I am a newbie in this matter, I do not know if I'm saying things that make sense. So someone could help me to understand (if I am wrong) ...

    Read the article

  • Rails 3: Validate combined values

    - by Cimm
    In Rails 2.x you can use validations to make sure you have a unique combined value like this: validates_uniqueness_of :husband, :scope => :wife In the corresponding migration it could look like this: add_index :family, [:husband, :wife], :unique => true This would make sure the husband/wife combination is unique in the database. Now, in Rails 3 the validation syntax changed and the scope attribute seems to be gone. It now looks like: validates :husband, :presence => true Any idea how I can achieve the combined validation in Rails 3? The Rails 2.x validations still work in Rails 3 so I can still use the first example but it looks so "old", are there better ways?

    Read the article

  • Any danger in calling flash messages html_safe?

    - by PreciousBodilyFluids
    I want a flash message that looks something like: "That confirmation link is invalid or expired. Click here to have a new one generated." Where "click here" is of course a link to another action in the app where a new confirmation link can be generated. Two drawbacks: One, since link_to isn't defined in the controller where the flash message is being set, I have to put the link html in myself. No big deal, but kind of messy. Number two: In order for the link to actually display properly on the page I have to html_safe the flash display function in the view, so now it looks like (using Haml): - flash.each do |name, message| = content_tag :div, message.html_safe This gives me pause. Everything else I html_safe has been HTML I've written myself in helpers and whatnot, but the contents of the flash hash are stored in a cookie client-side, and could conceivably be changed. I've thought through it, and I don't see how this could result in an XSS attack, but XSS isn't something I have a great understanding of anyway. So, two questions: 1. Is there any danger in always html_safe-ing all flash contents like this? 2. The fact that this solution is so messy (breaking MVC by using HTML in the controller, always html_safe-ing all flash contents) make me think I'm going about this wrong. Is there a more elegant, Rails-ish way to do this? I'm using Rails 3.0.0.beta3.

    Read the article

  • Exclusive filtering by tag

    - by KaptajnKold
    I'm using rails 3.0 and MySql 5.1 I have these three models: Question, Tag and QuestionTag. Tag has a column called name. Question has many Tags through QuestionTags and vice versa. Suppose I have n tag names. How do I find only the questions that have all n tags, identified by tag name. And how do I do it in a single query. (If you can convince me that doing it in more than one query is optimal, I'll be open to that) A pure rails 3 solution would be preferred, but I am not adverse to a pure SQL solution either.

    Read the article

  • Simple CanCan problem

    - by sscirrus
    I have just started with CanCan and here's a sample of the code: # Ability.rb def initialize(user) user ||= User.new can :read, Link end # view.html.erb <% if can? :read, @link %> ... <% end %> This is from the github repo for CanCan but this doesn't seem to work (it returns false and stops the ... code from running). When I change the view to <% if can? :read, Link %>, it works. But, this is different to the CanCan readme. Do you know where I'm going wrong here?

    Read the article

  • Rails 3 routing - what's best practice?

    - by Mattias
    Hi guys, I'm trying out Rails, and I've stumbled across an issue with my routing. I have a controller named "Account" (singular), which should handle various settings for the currently logged in user. class AccountController < ApplicationController def index end def settings end def email_settings end end How would I set-up the routes for this in a proper manner? At the moment I have: match 'account(/:action)', :to => 'account', :as => 'account' This however does not automagically produce methods like account_settings_path but only account_path Is there any better practice of doing this? Remember the Account controller doesn't represent a controller for an ActiveModel. If this is in fact the best practice, how would I generate links in my views for the actions? url_to :controller => :account, :action => :email_settings ? Thanks!

    Read the article

  • Rails plugin for generating dynamic / ajax crud interfaces compatible with Rails 3 beta?

    - by mikehansen
    Anyone know of some good gems or plugins to create dynamic / ajax crud interfaces for Rails 3 projects? I know active scaffold was popular before and it's been awhile since I have used it / any other gems similar to this (I usually just write it myself). I like the direction that the formtastic gem (http://github.com/justinfrench/formtastic) is headed and wonder what else people are combining with it. Also I like the generators approach that Ryan Bates uses and he appears to be making updates for Rails 3. Anything else I am missing here? (I am also open to gems not compatible with Rails 3 too I guess, I can always make a contribution and try to help them get to the next phase. ;)) PS - Really stackoverflow, only one hyperlink?? lame.

    Read the article

  • Rails 3 Timezone error

    - by Juan
    I am struggling with time zone support in Rails 3 beta and I would like to know if it is a bug or if I am doing something wrong. He is the problem: > Time.zone = 'Madrid' # it is GMT+2 = "Madrid" > c = Comment.new = #<Comment id: nil, title: "", pub_at: nil> > c.pub_at = Time.zone.parse('10:00:00') = Mon, 31 May 2010 10:00:00 CEST +02:00 > c.save > c = #<Comment id: 3, title: "", pub_at: "2010-05-31 08:00:00"> > c.reload = #<Comment id: 3, title: "", pub_at: "2010-05-31 08:00:00"> ruby-1.8.7-p249 c.pub_at = Mon, 31 May 2010 13:00:00 CEST +02:00 As you can see, the pub_at attribute is stored correctly in the database but when it is retrieved it adds 3 hours and I suspect that it is because it is using my local machine timezone that is in GMT-3. The same sequence of commands in rails 2.3.5 works perfectly. Any toughts? Should I report a ticket?

    Read the article

  • Ajax routes in Rails 3

    - by Jatin
    In my Rails 2.3 application, the following routes were working properly map.ajax 'ajax', :controller => 'widgetresponse_controller' , :action => 'getWidgetJson' When I migrated to Rails 3, I tried a number of new routes, to get this working but none of them worked. 1. match 'ajax' => 'widgetresponse#getWidgetJson', :as => :ajax 2. match 'ajax' => 'widgetresponse_controller#getWidgetJson', :as => :ajax 3. get 'widgetresponse/getWidgetJson', :as => :ajax 4. get 'widgetresponse/getWidgetJson' Its a very basic question to ask, but I don't know what I am doing wrong.

    Read the article

  • Rails - Ability to Enable/Disable Links on a View?

    - by AnApprentice
    Hello, I have a UserMailer View that has several link_to's like so: <%= link_to('XXXXXXXX Link Title', item_url(@item, :only_path => false), :style => 'color:#5196E3;text-decoration:underline;') %> The page has several different links. I'd like to know if there is a way to globally set in the view to enable or disable the links. If enabled, the above would run like normal, if not the block above would just show the text (XXXXXXXX Link Title) and not be linked? Any ideas other than wrapping every link_to inside a IF statement? Thanks

    Read the article

  • Rails Seed confusion

    - by sscirrus
    I'm having trouble seeding my database using seed.rb, specifically where table relationships are concerned. Here's a sample of the code: # seed.rb user = User.find_or_create_by_login( :login => "myname", :email => "[email protected]", :user_type => "Admin", :password => "admin", :password_confirmation => "admin") project = Project.find_or_create_by_user_id( :user_id => user.id, :name => "Test Project") When project is created (along with other unrelated parameters I've left out from above), user_id is empty. How can I get this to work?

    Read the article

  • How do I configure integration tests using rspec 2?

    - by Jamie Monserrate
    I need to have different settings for my unit tests and different settings for my integration tests. Example For unit tests, I would like to do WebMock.disable_net_connect!(:allow_localhost => true) And for integration tests, I would like to do WebMock.allow_net_connect! Also, before the start of an integration test, I would like to make sure that solr is started. Hence I want to be able to call config.before(:suite) do SunspotStarter.start end BUT, only for integration tests. I do not want to start my solr if its a unit test. How do I keep their configurations separate? Right now, I have solved this by keeping my integration tests in a folder outside the spec folder, which has its own spec_helper. Is there any better way?

    Read the article

  • How to get attribute of a model saved in instance variable

    - by Nazar
    I am writing a plugin, in which i define a new relation dynamically with in plugin. Sample code is given below module AttachDocumentsAs @as = nil def attach_documents_as(*attachment_as) attachment_as = attachment_as.to_a.flatten.compact.map(&:to_sym) @as = attachment_as.first class_inheritable_reader(@as) class_eval do has_many @as, :as => :attachable, :class_name=>"AttachDocuments::Models::AttachedDocument" accepts_nested_attributes_for @as end end end now in any model i used it as class Person < AtiveRecord::Base attach_documents_as :financial_documents end Now want to access want to access this attribute of the class in overloaded initialize method like this def initialize(*args) super(*args) "#{@as}".build end But it is not getting required attribute, can any one help me in it. I want to build this relation and set some initial values. Waiting for guidelines from all you guys.

    Read the article

  • Rails 3 NameError (cannot remove Object::Version) error

    - by Jeff D
    Can anyone point me at what might be causing this error? There is no ApplicationTrace, and it locks the server hard on my development machine. I think it has something to do with the way rails reloads your classes in development mode, and it appears to have something to do with a Version constant. I can't find a reference to this though. Can anyone point me in the direction of what would cause this? activesupport (3.0.3) lib/active_support/dependencies.rb:645:in `remove_const' activesupport (3.0.3) lib/active_support/dependencies.rb:645:in `remove_constant' activesupport (3.0.3) lib/active_support/dependencies.rb:645:in `instance_eval' activesupport (3.0.3) lib/active_support/dependencies.rb:645:in `remove_constant' activesupport (3.0.3) lib/active_support/dependencies.rb:521:in `remove_unloadable_constants!' activesupport (3.0.3) lib/active_support/dependencies.rb:521:in `each' activesupport (3.0.3) lib/active_support/dependencies.rb:521:in `remove_unloadable_constants!' activesupport (3.0.3) lib/active_support/dependencies.rb:317:in `clear' railties (3.0.3) lib/rails/application/bootstrap.rb:60:in `_callback_after_7' activesupport (3.0.3) lib/active_support/callbacks.rb:419:in `_run_call_callbacks' actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call' rack (1.2.1) lib/rack/sendfile.rb:107:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call' railties (3.0.3) lib/rails/rack/logger.rb:13:in `call' rack (1.2.1) lib/rack/runtime.rb:17:in `call' activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.2.1) lib/rack/lock.rb:11:in `call' rack (1.2.1) lib/rack/lock.rb:11:in `synchronize' rack (1.2.1) lib/rack/lock.rb:11:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call' railties (3.0.3) lib/rails/application.rb:168:in `call' railties (3.0.3) lib/rails/application.rb:77:in `send' railties (3.0.3) lib/rails/application.rb:77:in `method_missing' railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.2.1) lib/rack/content_length.rb:13:in `call' rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:162:in `start' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:95:in `start' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:92:in `each' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:92:in `start' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:23:in `start' /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/webrick/server.rb:82:in `start' rack (1.2.1) lib/rack/handler/webrick.rb:13:in `run' rack (1.2.1) lib/rack/server.rb:213:in `start' railties (3.0.3) lib/rails/commands/server.rb:65:in `start' railties (3.0.3) lib/rails/commands.rb:30 railties (3.0.3) lib/rails/commands.rb:27:in `tap' railties (3.0.3) lib/rails/commands.rb:27 script/rails:6:in `require' script/rails:6

    Read the article

  • Rails - any fancy ways to handle 404s?

    - by jyoseph
    I have a rails app I built for an old site I converted from another cms (in a non-rails language, hehe). Most of the old pages are mapped to the new pages using routes.rb. But there are still a few 404s. I am a rails newb so I'm asking if there are any advanced ways to handle 404s. For example, if I was programming in my old language I'd do this: Get the URL (script_name) that was being accessed and parse it. Do a lookup in the database for any keywords, ids, etc found in the new URL. If found, redirect to the page (or if multiple records are found, show them all on a results page and let user choose). With rails I'd probably want to do :status = :moved_permanently I'm guessing? If not found, show a 404. Are there any gems/plugins or tutorials you know of that would handle such a thing, if it's even possible. Or can you explain on a high level how that can be done? I don't need a full code sample, just a push in the right direction. PS. It's a simple rails 3 app that uses a single Content model.

    Read the article

  • How do I do a join in ActiveRecord after records have been returned?

    - by Russ Bradberry
    I am using ActiveRecord in Rails 3 to pull data from two different tables in two different databases. These databases can not join on each other, but I have the need to do a simple join after-the-fact. I would like to preserve the relation so that I can chain it down the line. here is a simplified version of what I am doing browsers = Browser.all # <-- this is fairly small and can reside in memory events = Event.where(:row_date=>Date.today).select(:name, :browser_id) So as you can see, I want to join browsers in on the events relation, where browser_id should equal browsers.name. events is a relation and I can still add clauses to it down the line, so I dont want to run the query on the db just yet. How would I accomplish this?

    Read the article

  • How to add a new custom resource to routes Rails 3

    - by Jeroen janssen
    How do I add a custom route for a new resource in the Rails 3 routes? I know how to do it for collections and members but this style doesn't seem to be working for new resources. Is this a bug or am I doing something wrong? So these work: collection do get :wish end member do get :wish end But this doesn't work: new do get :wish end

    Read the article

  • Rails 3: habtm migration, primary key issue

    - by Brian Wigginton
    I'm trying to setup a migration file for a habtm relationship, however when I run the migration I'm getting the following error: Primary key is not allowed in a has_and_belongs_to_many join table (parts_vehicles). Here is my migration file (20110111035950_create_parts_vehicles.rb): class CreatePartsVehiclesJoinTable < ActiveRecord::Migration def self.up create_table :parts_vehicles, :id => false do |t| t.integer :part_id t.integer :vehicle_id end end def self.down drop_table :parts_vehicles end end The documentation example states to use :id => false to disable a primary key from being generated, but I'm still getting the error.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12  | Next Page >