Search Results

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

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

  • Preloading data without messing up association when data is loaded the 2nd time.

    - by denniss
    This is how my model looks like User belongs_to :computer Computer has_many :user Users are created when people register for an account on the web site but computers are pre-loaded data that I create in seeds.rb/some .rake file. All is fine and good when the app is first launched and people start registering and get associated with the right computer_id. However, suppose I want to add another computer to the list Computer.destroy_all Computer.create({:name => "Akane"}) Computer.create({:name => "Yoda"}) Computer.create({:name => "Mojito"}) #newly added running the rakefile the second time around will mess up the associations because computer_id in the User table refer to the old id in Computer table. Since I have run the script above, the id keeps incrementing without any regard to the association that user has to it. Question: Is there a better way for me to pre-load data without screwing up my association? I want to be able to add new Computer without having to destroy the user's table. Destroying the computer table is fine with me and rebuilding it again but the old association that the existing users have must stay intact.

    Read the article

  • Add Shortcut to Nested Route

    - by wakeless
    I'm using nested routes and I want to provide some sort of a shortcut method. (I'm using RoR 3.0) The routes look like this. resources :countries do resources :regions do resources :wineries end end To access a winery route I want to be able to define a function that removes the need to specify a country and region each time. Like: def winery_path(winery) country_region_winery_path (winery.country, winery.region, winery) end Where should I do this? How can I get that to be available whereever url_for is available?

    Read the article

  • Display a flash message for a specific loggedin user upon receiving request.

    - by ShenoudaB
    Dears, how can i trigger a prompt (or flash message with links) display (notifying) for one of the logged in agent (specific agent screen) on my web application when receiving a request from a client. using rails and jquery. as my application is serving a call center, and the my client request ... when a call coming to the system a prompt appears to an agent this call dedicated to with some info from the call.

    Read the article

  • access properties of current model in has_many declaration

    - by seth.vargo
    Hello, I didn't exactly know how to pose this question other than through example... I have a class we will call Foo. Foo :has_many Bar. Foo has a boolean attribute called randomize that determines the order of the the Bars in the :has_many relationship: class CreateFoo < ActiveRecord::Migration def self.up create_table :foos do |t| t.string :name t.boolean :randomize, :default => false end end end   class CreateBar < ActiveRecord::Migration def self.up create_table :bars do |t| t.string :name t.references :foo end end end   class Bar < ActiveRecord::Base belongs_to :foo end   class Foo < ActiveRecord::Base # this is the line that doesn't work has_many :bars, :order => self.randomize ? 'RAND()' : 'id' end How do I access properties of self in the has_many declaration? Things I've tried and failed: creating a method of Foo that returns the correct string creating a lambda function crying Is this possible? UPDATE The problem seems to be that the class in :has_many ISN'T of type Foo: undefined method `randomize' for #<Class:0x1076fbf78> is one of the errors I get. Note that its a general Class, not a Foo object... Why??

    Read the article

  • Mixing has_one and has_and_belongs_to_many associations

    - by Thomas
    I'm trying to build a database of urls(links). I have a Category model that has and belongs to many Links. Here's the migration I ran: class CreateLinksCategories < ActiveRecord::Migration def self.up create_table :links_categories, :id => false do |t| t.references :link t.references :category end end def self.down drop_table :links_categories end end Here's the Link model: class Link < ActiveRecord::Base validates :path, :presence => true, :format => { :with => /^(#{URI::regexp(%w(http https))})$|^$/ } validates :name, :presence => true has_one :category end Here's the category model: class Category < ActiveRecord::Base has_and_belongs_to_many :links end And here's the error the console kicked back when I tried to associate the first link with the first category: >>link = Link.first => #<Link id: 1, path: "http://www.yahoo.com", created_at: "2011-01-10... >>category = Category.first => #<category id : 1, name: "News Site", created_at: "2011-01-11... >>link.category << category => ActiveRecord::StatementInvalid: SQLite3::Exception: no such column : categories.link_id: Are my associations wrong or am I missing something in the database? I expected it to find the links_categories table. Any help is appreciated.

    Read the article

  • How to run Rails 3 application on localhost/<my_port> ?

    - by Misha Moroshko
    To run Rails application on Windows I do: cd < app_dir rails server I see the following: => Booting WEBrick => Rails 3.0.1 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-01-12 20:32:07] INFO WEBrick 1.3.1 [2011-01-12 20:32:07] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32] [2011-01-12 20:32:07] INFO WEBrick::HTTPServer#start: pid=5812 port=3000 Question 1 Why port 3000 is selected ? Where is it configured ? Question 2 How could I run 2 applications in parallel ? I guess I need to configure one of them to be on other port (like 3001). How should I do this ?

    Read the article

  • Rails always include (join) on initialize

    - by Seth
    Hello, I have a User model as illustrated below: class User < ActiveRecord belongs_to :college belongs_to :class_level end I want to ALWAYS join with those other two tables returning one simplified User object. How do I accomplish this in my User model. I'm aware that I can do this in another model: class Foo < ActiveRecord has_many :users, :include => [:college, :class_level] end But I want to do this in my User model, so Foo.users will either be eager loaded OR be joined already. Is there a way to create an initialize this in the User model?

    Read the article

  • Rails 3: How not to include column's name in a validation message without plugins ?

    - by Misha Moroshko
    I have the following validation: validates_presence_of :price, :message => "my message" and I get the following error when the price is blank: Price my message Is there a way not to include the column name (price) in the message ? I tried to do: validates_presence_of :price, :message => "^ my message" as suggested here, but it didn't work for me. I got the following message: Price ^ my message

    Read the article

  • Rails: include related object in JSON output

    - by Codezy
    I have a note class that belongs to a user (ie a user can create many notes). clip from my notes controller class NotesController < ApplicationController before_filter :authenticate_user! respond_to :html, :xml, :json # GET /notes # GET /notes.xml def index @notes = Note.includes(:user).order("created_at DESC") respond_with @notes end When I ask for the index in json results for example /notes.json, it returns the notes but only returns user_id for the user object. I would like it to also include user.username (and would be curious how to have the whole user object embedded). Bonus question: I could not find a way to make the column show as author_id and have it relate back to user. If this is easy to do, how do you do it?

    Read the article

  • Network ActiveRecord relation with Rails

    - by Zag zag..
    Hi, I have a has and belongs to many relation between User and Article models, and I would like to link them even if an article if not hosted on the same database then a user. For example, If an article exists at foo.com/articles/3 and a user exists at bar.com/users/1, If would like to be able to do from foo.com web interface or bar.com web interface this kind of query: a_user.articles (or an_article.users). I think this can be possible adding a field like "url" in users and articles tables. But I don't know how to process for ActiveRecord. My Article model looks like this: class Article < ActiveRecord::Base has_and_belongs_to_many :users end Is there yet some example of project using this kind of relation over internet? Many thanks

    Read the article

  • rails 3 how to automatically post user_id in column of comments

    - by user568502
    hi, im totally new to rails. here my question: i made an app with articles and comments and use devise for authentication sadly im only able to post 1 hyperlink so this is the middle part of my post with the files at gist: https://gist.github.com/771366 the article_id is pre selected in the comments/_form - but the user_id isnt. i googled a lot, tried value = session[:user_id] and others, but nothing worked would be great if someone could tell me how it works ^^ thx

    Read the article

  • Redirect on catching an exception in a method in the model

    - by Arkid
    I am using Authlogic-connect to connect various service providers. There is a method in user.rb def complete_oauth_transaction token = token_class.new(oauth_token_and_secret) old_token = token_class.find_by_key_or_token(token.key, token.token) token = old_token if old_token if has_token?(oauth_provider) self.errors.add(:tokens, "you have already created an account using your #{token_class.service_name} account, so it") else self.access_tokens << token end end When a service provider is already added it gives the error as stated in the has_token? method and the page breaks. I need to redirect the app to the same page and flash the error. How do i do this? I have overridden the method in my own user.rb so that I can change the code.

    Read the article

  • Create a select tag with some options grouped and others not grouped

    - by dontangg
    I'm using Rails 3. I want to create a select tag with some options grouped and others not grouped. Options would look something like this: Income Auto Fuel Maintenance Home Maintenance Mortgage In this example, Income is not a group, but Auto and Home are. I see three helper methods grouped_options_for_select and grouped_collection_select, option_groups_from_collection_for_select. Is there a way to use a helper to do this or will I have to generate the HTML myself? I imagine I could use two different helpers to create the options and just append the results of both.

    Read the article

  • How to get notified of changes on a read only table? (I.e., Price drop notifications.)

    - by mirthlab
    Let's say I have these tables/models: Product - id - last_updated_date - name - price User - id - name Wishlist - id - user_id - product_id The Product table has a few million records and is being updated automatically each night via a data import (inserting into a new table, dropping the old one). I basically have read-only access to that table/model. If a product is on a user's wishlist and the price drops, I'd like to be able to notify that user. What methods can be used to do this? I have a couple of ideas: Keep track of the Product.last_updated_date in the wishlist model and periodically poll the product table to see if it has been updated. This sounds like a horrible/non-scaleable solution. Some sort of Postgres View or Function that triggers when the Product table is updated? I'm new to postgres so I'm not yet sure if this is even possible. Something amazing that you will suggest that I haven't thought of :) Any help in the right direction is greatly appreciated!

    Read the article

  • Rails 3: How to validate that A < B where A and B are both model attributes ?

    - by Misha Moroshko
    I would like to validate that customer_price >= my_price. I tried the following: class Product < ActiveRecord::Base attr_accessor :my_price validates_numericality_of :customer_price, :greater_than_or_equal_to => my_price ... end (customer_price is a column in the Products table in the database, while my_price isn't.) Here is the result: NameError in ProductsController#index undefined local variable or method `my_price' for #<Class:0x313b648> What is the right way to do this in Rails 3 ?

    Read the article

  • How do you submit a rails 3 form without refreshing the page?

    - by Anthony H
    I've seen this done using ajax & php, but not rails 3. I've tried using: <%= form_for(:technician, :url => {:controller => 'pos', :action => 'create_ticket'}, :remote => true) do |f| %> but the page still refreshes each time. I'm building a point of sale program, so I don't want the page to refresh. How do I send the form data to the controller to process and store in the database without refreshing?

    Read the article

  • take performance as the only criterion for a smal site, which framework should I choose on a shared

    - by john
    Dear friends, I'm trying to set up a small full functional website for a small community on a shared hosting. Scientific computing is quite heavy. Scalability is not important. The only criterion is performance. Which framework would you suggest among the following:(or more) from your list) 1)Ruby on Rails 2) Grails 3) asp.net 4) zend I'm really new to this area, only starting reading some books and googling different blogs...so your expertise is really appreciated! thanks!

    Read the article

  • Rails 3 Routing help

    - by Rod Nelson
    OK i'm new to rails 3 and the new routing is driving me mad. I just a good example i was looking at the info on http://rizwanreza.com/2009/12/20/revamped-routes-in-rails-3 but it don't make sense to me. i need an example please! I have my root down that's not hard. I have Site as my controller and i have index help and about then i have a second controller users with index and register on the register page i have 3 text boxes and a submit when i hit submit i get Routing Error No route matches "/user/register" if you need me to i will post my routes file

    Read the article

  • Two forms are being called from one view.One encodes the russian text the doesn't.

    - by Daniel
    The menu I want to show to the users changes depending on their rights After user authentication I redirect to my menu action which calls its view access/menu.html.erb <% if admin? %> <%form_for(:user, :url => {:controller => 'admin_users',:name => session[:username]}) do |admin|%> <ul><h2>Administrator: <%=session[:username]%></h2></ul> <%= render(:partial =>'admin_form',:locals => {:admin => admin})%> <%end%> <%else%> <%form_for(:user, :url => {:controller => 'students',:name => session[:username]}) do |student|%> <ul><h2>???????: <%=session[:surname].to_s + " " + session[:name].to_s%></h2></ul> <%= render(:partial =>'student_form',:locals => {:student => student})%> <%end%> <%end%> And the forms look: _student_form: <table> <ul> <li><%=link_to '?????',{:controller => 'students'}%></li> </ul> <ul> <li><%=link_to '?????? ?????????',{:controller => 'students'}%></li> </ul> <ul> <li><%=link_to '???????? ?????? ????',{:controller => 'students'}%></li> </ul> <ul> <li><%=link_to '???????? ??????',{:controller => 'students'}%></li> </ul> <ul> <td>&nbsp;</td> </ul> </table> _admin_form: <table> <ul> <li><%=link_to '?????????? ????????????????',{:controller => 'AdminUsers',:role_id => 1}%></li> </ul> <ul> <li><%=link_to '?????????? ????????',{:controller => 'AdminUsers',:role_id => 2}%></li> </ul> <ul> <li><%=link_to '?????????? ??????????',{:controller => 'AdminUsers',:role_id => 3}%></li> </ul> <ul> <li><%=link_to '?????????? ???????????',:controller => 'subjects'%></li> </ul> <ul> <td>&nbsp;</td> </ul> </table> If a log in as a student I get: But if I log in as an administrator I get How can this be posible??

    Read the article

  • Attributes passed to .build() dont show up in the query

    - by Sebastian
    Hi there guys! Hope your all enjoying your hollydays. Ive run into a pretty funny problem when trying to insert rows into a really really simple database table. The basic idea is pretty simple. The user selects one/multiple users in a multiselect which are supposed to be added to a group. This piece of code will insert a row into the user_group_relationships table, but the users id always @group = Group.find(params[:group_id]) params[:newMember][:users].each do |uid| # For debugging purposes. puts 'Uid:'+uid @rel = @group.user_group_relationships.build( :user_id => uid.to_i ) @rel.save end The user id always gets inserted as null even though it is clearly there. You can see the uid in this example is 5, so it should work. Uid:5 ... SQL (0.3ms) INSERT INTO "user_group_relationships" ("created_at", "group_id", "updated_at", "user_id") VALUES ('2010-12-27 14:03:24.331303', 2, '2010-12-27 14:03:24.331303', NULL) Any ideas why this fails?

    Read the article

  • form_for [@parent,@son],:remote=>true not asking for JS

    - by Cibernox
    Hi. I have a plain old form. That form is used to create new objects of a nested model. #restaurant.rb has_many :courses #courses.rb belongs_to :restaurant #routes.rb resources :restaurants do resources :courses end In my views(in haml), i have that code: %li.course{'data-random'=>random} = form_for([restaurant,course], :remote=>true) do |f| .name= f.text_field :name, :placeholder=>'Name here' .cat= f.hidden_field :category .price= f.text_field :price,:placeholder=>'Price here' .save = hidden_field_tag :random,random = f.submit "Save" I espected that form to be answered by action create of courses_controller with JS (create.js.erb), but it is submited like a normal form, and is answered with html. What am I doing wrong? This problem is similar to this but the only answer don't make sense to me. Thanks Inside

    Read the article

  • Rspec and Rails 3 - Problem Validating Nested Attribute Collection Size

    - by MunkiPhD
    When I create my Rspec tests, I keep getting a validation of false as opposed to true for the following tests. I've tried everything and the following is the measly code that I have now - so if it's waaaaay wrong, that's why. class Master < ActiveRecord::Base attr_accessible :name, :specific_size # Associations ---------------------- has_many :line_items accepts_nested_attributes_for :line_items, :allow_destroy => true, :reject_if => lambda { |a| a[:item_id].blank? } # Validations ----------------------- validates :name, :presence => true, :length => {:minimum => 3, :maximum => 30} validates :specific_size, :presence => true, :length => {:minimum => 4, :maximum => 30} validate :verify_items_count def verify_items_count if self.line_items.size < 2 errors.add(:base, "Not enough items to create a master") end end end And here it the items model: class LineItem < ActiveRecord::Base attr_accessible :specific_size, :other_item_type_id # Validations -------------------- validates :other_item_type_id, :presence => true validates :master_id, :presence => true validates :specific_size, :presence => true # Associations --------------------- belongs_to :other_item_type belongs_to :master end The RSpec Tests: before(:each) do @master_lines = [] @master_lines << LineItem.new(:other_item_type_id => 1, :master_id => 2, :specific_size => 1) @master_lines << LineItem.new(:other_item_type_id => 2, :master_id => 2, :specific_size => 1) @attr = {:name => "Some Master", :specific_size => "1 giga"} end it "should create a new instance given a valid name and specific size" do @master = Master.create(@attr) line_item_one = @master.line_items.build(:other_item_type_id => 1, :specific_size => 1) line_item_two = @master.line_items.build(:other_item_type_id => 2, :specific_size => 2) @master.line_items.size === 2 @master.should be_valid end it "should have at least two items to be valid" do master = Master.new(:name => "test name", :specific_size => "1 mega") master_item_one = LineItem.new(:other_item_type_id => 1, :specific_size => 2) master_item_two = LineItem.new(:other_item_type_id => 2, :specific_size => 1) master.line_items << master_item_one master.should_not be_valid master.line_items << master_item_two master.line_items.size.should === 2 master.should be_valid end I'm very new to Rspec and Rails - and I've been failing at this for the past couple of hours. Thanks for any help in advance.

    Read the article

  • How/When/Where to Extend Gem Classes (via class_eval and Modules) in Rails 3?

    - by viatropos
    What is the recommended way to extend class behavior, via class_eval and modules (not by inheritance) if I want to extend a class buried in a Gem from a Rails 3 app? An example is this: I want to add the ability to create permalinks for tags and categories (through the ActsAsTaggableOn and ActsAsCategory gems). They have defined Tag and Category models. I want to basically do this: Category.class_eval do has_friendly_id :title end Tag.class_eval do has_friendly_id :title end Even if there are other ways of adding this functionality that might be specific to the gem, what is the recommended way to add behavior to classes in a Rails 3 application like this? I have a few other gems I've created that I want to do this to, such as a Configuration model and an Asset model. I would like to be able to add create an app/models/configuration.rb model class to my app, and it would act as if I just did class_eval. Anyways, how is this supposed to work? I can't find anything that covers this from any of the current Rails 3 blogs/docs/gists.

    Read the article

  • Specifying Entire Path As Optional Rails 3.0.0

    - by Kevin Sylvestre
    I want to create a Rails 3 route with entirely optional parameters. The example route is: match '(/name/:name)(/height/:height)(/weight/:weight)' => 'people#index' The route works if I specify it as: match '/people(/name/:name)(/height/:height)(/weight/:weight)' => 'people#index' But I want to have this as the root URL. Thanks.

    Read the article

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