Search Results

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

Page 148/378 | < Previous Page | 144 145 146 147 148 149 150 151 152 153 154 155  | Next Page >

  • Ruby on Rails: Find records based on a method in the model?

    - by sjsc
    I'm looking to use named_scope to find records based on a method in the model. Right now I have in my Order.rb model: def self.paid collect { |order| order if order.paid? } end # the method def paid order.payments.total >= order.total_price end That works, but I can't chain it if I have a shipped named_scope: named_scope :shipped, :conditions => "shipped is true" And I wanted to do: Order.paid.shipped which doesn't work. Any ideas?

    Read the article

  • Ruby on Rails testing: How can I test or at the very least see a form_for's error_messages_for?

    - by williamjones
    I'm working on creating a tests, and I can't figure out why the creation of a model from a form_for is failing in the test but works in real browsers. Is there a straightforward way for me to see what the problems are in the model creation? Even better would be, is there a straightforward way for me to test the error outputs that I access via error_messages_for? In that case, I'd like to also add in tests that make sure that malformed forms are outputting the correct errors.

    Read the article

  • Rails and Prawn PDF - add current item ID to filename?

    - by dannymcc
    Hi Everyone, I have two PDFs that are made "on the fly" using Prawn PDF. The PDFs are called jobsheet.pdf and discharge.pdf - their URL's are: railsroot/kases/IDNO/jobsheet.pdf railsroot/kases/IDNO/discharge.pdf I am trying to work out how to automagically append the filename with the ID number: railsroot/kases/IDNO/jobsheet_IDNO.pdf railsroot/kases/IDNO/discharge_IDNO.pdf To create the PDFs the code is as follows: Kases Controller def jobsheet @kase = Kase.find(params[:id]) respond_to do |format| format.html {} # jobsheet.html.erb format.xml { render :xml => @kase } format.pdf { render :layout => false } prawnto :prawn => { :background => "#{RAILS_ROOT}/public/images/jobsheet.png", :left_margin => 0, :right_margin => 0, :top_margin => 0, :bottom_margin => 0, :page_size => 'A4' } end end # GET /kases/1 # GET /kases/1.xml def discharge @kase = Kase.find(params[:id]) respond_to do |format| format.html { } # discharge.html.erb format.xml { render :xml => @kase } format.pdf { render :layout => false } prawnto :prawn => { :background => "#{RAILS_ROOT}/public/images/discharge.png", :left_margin => 0, :right_margin => 0, :top_margin => 0, :bottom_margin => 0, :page_size => 'A4' } end end Routes map.resources :kases, :member => { :discharge => :get } map.resources :kases, :member => { :jobsheet => :get } To view the PDF's I use the following links: jobsheet_kase_path(@kase, :format => 'pdf') discharge_kase_path(@kase, :format => 'pdf') Is this even possible? Thanks, Danny

    Read the article

  • How to integrate Facebook the new Graph Api with Authlogic in Ruby on Rails?

    - by amrnt
    I've began with a new project using Authlogic system for Authorization. And I'm now wondering how could I connect Facebook oAuth sessions with my Authlogic session! First of all I want to use and Authlogic-oAuth Gems/Plugins, I what I want to use are just http://github.com/intridea/oauth2 and the interesting http://github.com/nsanta/fbgraph and associate them all with Authlogic. I tried using Authlogic with authlogic-connect extension, but It didnt fill up my needs. And I think the three of the amazing gems above togother will make things done in quality and as I want. Thanks in advance.

    Read the article

  • RSpec install error: "Could not find autotest in any of your source paths"

    - by Vinicius Pinto
    When I run: rails generate rspec:install I get this output: identical .rspec exist spec identical spec/spec_helper.rb Could not find "autotest" in any of your source paths. Your current source paths are: (..)/rails_projects/sample_app/lib/templates/rspec/install (..)/rspec-rails-2.3.0/lib/generators/rspec/install/templates I'm new to RSpec, Rails and Ruby. Any tips on how make this work?

    Read the article

  • How to specify a route member inside a block in Rails?

    - by yuval
    The following code: map.resources :users, :has_many => :items Could be written like this in a block: map.resources :users do |user| user.resources :items end How could I write the following code in a block? map.resources :users, :member => { :start => :post } Also, where could I find documentation on writing routes in blocks? The Routes Documentation does not seem to show it. Thank you!

    Read the article

  • How can I refactor out needing so many for-loops in rails?

    - by Angela
    I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many Contacts Campaign also has many templates for EVent (Email, Call, and Letter). I need a list of all the Emails, Calls and Letters that are "overdue" for every Contact that belongs to a Campaign. Overdue is determined by a from_today method which looks at the date the Contact was entered in the system and the number of days that needs to pass for any given Event. from_today() outputs the number of days from today that the Event should be done for a given Contact. Here is what I've done, it works for all Emails in a Campaign across all contacts. I was going to try to create another each do loop to change the class names. Wasn't sure where to begin: named_scope, push some things into a method, etcetera, or -- minimum to be able to dynamically change the class names so at least it loops three timees across the different events rather than repeating the code three times: <% @campaigns.each do |campaign| %> <h2><%= link_to campaign.name, campaign %></h2> <% @events.each do |event| %> <%= event %> <% for email in campaign.emails %> <h4><%= link_to email.title, email %> <%= email.days %> days</h4> <% for contact in campaign.contacts.find(:all, :order => "date_entered ASC" ) %> <% if (from_today(contact, email.days) < 0) %> <% if show_status(contact, email) == 'no status'%> <p> <%= full_name(contact) %> is <%= from_today(contact,email.days).abs%> days overdue: <%= do_event(contact, email) %> </p> <% end %> <% end %> <% end %> <% end %> <% end %> <% end %>

    Read the article

  • Why is Rails is trying to rerun migrations on production?

    - by ryeguy
    On my server when deploying the app for the first time, I ran rake db:setup which loads my entire migration history from schema.rb. Now I have more stuff I want to add, but when I run rake db:migrate on my server I realize it's trying to run my very first migration, which is failing since the table obviously exists. Examining the schema_migrations table on my production server, I realize it only has one entry in it, which is the migration that was the most current at the time of the initial deployment. Isn't it supposed to have the entire migration history in it? If so, what caused this? If not, why is it doing this?

    Read the article

  • why is this rails association loading individually after an eager load?

    - by codeman73
    I'm trying to avoid the N+1 queries problem with eager loading, but it's not working. The associated models are still being loaded individually. Here are the relevant ActiveRecords and their relationships: class Player < ActiveRecord::Base has_one :tableau end Class Tableau < ActiveRecord::Base belongs_to :player has_many :tableau_cards has_many :deck_cards, :through => :tableau_cards end Class TableauCard < ActiveRecord::Base belongs_to :tableau belongs_to :deck_card, :include => :card end class DeckCard < ActiveRecord::Base belongs_to :card has_many :tableaus, :through => :tableau_cards end class Card < ActiveRecord::Base has_many :deck_cards end and the query I'm using is inside this method of Player: def tableau_contains(card_id) self.tableau.tableau_cards = TableauCard.find :all, :include => [ {:deck_card => (:card)}], :conditions => ['tableau_cards.tableau_id = ?', self.tableau.id] contains = false for tableau_card in self.tableau.tableau_cards # my logic here, looking at attributes of the Card model, with # tableau_card.deck_card.card; # individual loads of related Card models related to tableau_card are done here end return contains end Does it have to do with scope? This tableau_contains method is down a few method calls in a larger loop, where I originally tried doing the eager loading because there are several places where these same objects are looped through and examined. Then I eventually tried the code as it is above, with the load just before the loop, and I'm still seeing the individual SELECT queries for Card inside the tableau_cards loop in the log. I can see the eager-loading query with the IN clause just before the tableau_cards loop as well. EDIT: additional info below with the larger, outer loop Here's the larger loop. It is inside an observer on after_save def after_save(pa) @game = Game.find(turn.game_id, :include => :goals) @game.players = Player.find :all, :include => [ {:tableau => (:tableau_cards)}, :player_goals ], :conditions => ['players.game_id =?', @game.id] for player in @game.players player.tableau.tableau_cards = TableauCard.find :all, :include => [ {:deck_card => (:card)}], :conditions => ['tableau_cards.tableau_id = ?', player.tableau.id] if(player.tableau_contains(card)) ... end end end

    Read the article

  • Rails: how can I access the request object outside a helper or controller?

    - by rlandster
    In my application_helper.rb file I have a function like this: def internal_request? server_name = request.env['SERVER_NAME'] [plus more code...] end This function is needed in controllers, model, and views. So, I put this code in a utility function file in the lib/ directory. However, this did not work: I got complaints about request not being defined. How can I access the request object in a file in the lib/ directory?

    Read the article

  • How to save some values from an array in a controller in Rails?

    - by Alfred Nerstu
    I've got a links array that I'm saving to a database. The problem is that the records aren't saved in the order of the array ie links[1] is saved before links[2] and so on... This is a example from the view file: <p> <label for="links_9_label">Label</label> <input id="links_9_name" name="links[9][name]" size="30" type="text" /> <input id="links_9_url" name="links[9][url]" size="30" type="text" /> </p> And this is my controller: def create @links = params[:links].values.collect { |link| @user.links.new(link) } respond_to do |format| if @links.all?(&:valid?) @links.each(&:save!) flash[:notice] = 'Links were successfully created.' format.html { redirect_to(links_url) } else format.html { render :action => "new" } end end end Thanks in advance! Alfred

    Read the article

  • Rails, How can I combine multiple model attributes to create a unique permalink using permalink_fu?

    - by Ranknoodle
    Can Permalink_fu combine 2 or more model attributes to create a unique permalink? Let's say I have a Business Model, this model contains :name, :address, :phone, :city, :state, :country etc. attributes. Right now I have permalink set up in this model only for :name has_permalink :name So I would get "/biz/name". However I would like to combine the Business name, city, and a incremental number if there are more than 1 location in the city for that business. For example I would like to use: "/biz/joes-coffee-shack-chicago" for the permalink or if a multple location business "/biz/starbucks-chicago-92" Is this possible with the current permalink_fu plugin or some fork of permalink_fu? Or will this require some modification to the permalink_fu plugin?

    Read the article

  • how do I redirect from a subdirectory to another directory, but strip off the original subdirectory

    - by Eric Cope
    I have a Ruby on Rails app running on 12001. I am currently redirecting a subdomain to 127.0.0.1:12001 using some ReWriteCond detection. Now I want to redirect my subdirectory to that rails app. http[s]://domain.com/redmine to 127.0.0.1:12001 The current rules apply REQUEST_URI to the above rails path, but I need to strip "/redmine" from the front of REQUEST_URI... Any ideas?

    Read the article

  • In Rails, how can a record belong_to a single user, but also have multiple "secondary" users?

    - by Kuro
    In my app, I have a User model and a Project model. A user has_many assignments and each project belongs_to a user. But along with each project having an owner, the user who created it, I would like the owner be able to share it with others (so that the project gets shown on the other users' account along with their own). I imagine having to use has_many :through, and setting up a projects_users table with a user_id and a project_id. And I guess this would be the end result? Project.first.user # The creator of the project => #<User id: 1, name: 'andrew', etc...> Project.first.users # The users that the creator chose to share it with => [#<User id: 2 ...>, #<User id: 3 ...>] How would I go about doing this? Thanks!

    Read the article

  • How do I use XML Builder to create xml in rails?

    - by Angela
    I am trying the following, but the output XML is badly formed: def submit xml = Builder::XmlMarkup.new xml.instruct! xml.mail xml.documents xml.document xml.template xml.source "gallery" xml.name "Postcard: Image fill front" @xml_display = xml end I need it to look more like this: <?xml version="1.0" encoding="UTF-8"?> <mail> <documents> <document> <template> <source>gallery</source> <name>Postcard: Image fill front</name> </template> <sections> <section> <name>Text</name> <text>Hello, World!</text> </section> <section> <name>Image</name> <attachment>...attachment id...</attachment> </section> </sections> </document> </documents> <addressees> <addressee> <name>John Doe</name> <address>123 Main St</address> <city>Anytown</city> <state>AZ</state> <postal-code>10000</postal-code> </addressee> </addressees> </mail>

    Read the article

  • how do I get only the stack trace from my app in rails?

    - by codeman73
    The default behavior seems to be printing large stack traces like ArgumentError (too few arguments): app/controllers/players_controller.rb:55:in `format' app/controllers/players_controller.rb:55:in `create' /dh/passenger/lib/phusion_passenger/rack/request_handler.rb:92:in `process_request' /dh/passenger/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop' /dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:400:in `start_request_handler' /dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:351:in `handle_spawn_application' /dh/passenger/lib/phusion_passenger/utils.rb:184:in `safe_fork' /dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:349:in `handle_spawn_application' /dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `__send__' /dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `main_loop' /dh/passenger/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' /dh/passenger/lib/phusion_passenger/abstract_server.rb:163:in `start' /dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:209:in `start' /dh/passenger/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application' /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add' /dh/passenger/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application' /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize' /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' /dh/passenger/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application' /dh/passenger/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application' /dh/passenger/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application' /dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `__send__' /dh/passenger/lib/phusion_passenger/abstract_server.rb:352:in `main_loop' /dh/passenger/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' but I only want to see the stack trace from my app. In this case, it's the top 3 lines, which consist of the actual Error, and then the parts of my app. In this case I'd prefer to see this: ArgumentError (too few arguments): app/controllers/players_controller.rb:55:in `format' app/controllers/players_controller.rb:55:in `create' Is this possible?

    Read the article

  • How to get link_to in Rails output an SEO friendly url?

    - by Jason
    Hi, My link_to tag is: <%= link_to("My test title",{:controller=>"search", :action=>"for-sale", :id=> listing.id, :title => listing.title, :search_term => search_term}) %> and produces this ugly URL: http://mysite.com/search/for-sale/12345?title=premium+ad+%2B+photo+%5Btest%5D How can I get link_to to generate: http://mysite.com/search/for-sale/listing-title/search-term/12345 Been trying this a few different ways and cannot find much online, really appreciate any help!

    Read the article

< Previous Page | 144 145 146 147 148 149 150 151 152 153 154 155  | Next Page >