Search Results

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

Page 116/378 | < Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >

  • Sorting page flow for has_many in Rails

    - by Gareth
    I have a page flow allowing the user to choose an object ("Player") to add to a has_many :players association in another model. 1 => List existing players for object [Enter player name] 2 => List of matching players [Select player] 3 => Confirmation page [Press 'Add'] 4 => Done I want users to be able to choose "New Player" instead of selecting a player at step 2, in which case the user will go through the standard New Player process elsewhere on the site. However, after that's done, the user should return to step 3 with the new player in place. I don't know what the best way is to implement this. I don't want to duplicate the player creation code, but I don't want to dirty up the player creation code too much just for this case. I also don't want to start sticking IDs in the session if I can help it. It's fine in simple cases but if the user ever has two windows/tabs then things start behaving badly. What do you think?

    Read the article

  • Rails: associate model with two of its kind

    - by Patrick Oscity
    hi all, im trying to do this: class Event < ActiveRecord::Base belongs_to :previous_event has_one :event, :as => :previous_event, :foreign_key => "previous_event_id" belongs_to :next_event has_one :event, :as => :next_event, :foreign_key => "next_event_id" end because i want to enable the user to repeat events and change multiple oncoming events at the same time. what am i doing wrong, or is there another way of doing this? somehow i need to know about the previous and the next event, don't i? when i'm testing this in the consolewith Event.all[1].previous_event, i get the following error: NameError: uninitialized constant Event::PreviousEvent from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `const_missing' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2199:in `compute_type' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2195:in `compute_type' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:156:in `send' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:156:in `klass' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/belongs_to_association.rb:49:in `find_target' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:239:in `load_target' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:112:in `reload' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1250:in `previous_event' from (irb):2 what is going wrong here? thanks a ton for your help.

    Read the article

  • How do I form a Rails link_to with custom field value as parameter

    - by rwheadon
    I have an invoice form where I'm giving the user opportunity to apply coupons to the invoice total. These coupons are held in another Model and I am going to do a lookup on the Coupon code (something like "20OFFONFRIDAY") which I will use to find what the restrictions and benefits of the coupon. (and to see if it even exists at all) The invoice does not have "coupon_code" on it so I hand forged the field onto my form with html: <% if (@invoice.status == 'new') %> <input id="coupon_code" name="coupon_code" type="text"/> <% end %> and I am calling a controller method with link_to and would like something like the following jquery enhanced link_to to work: <%= link_to "Apply Coupon", { :controller=>"invoices", :id=>@invoice.id, :coupon_code=>$('.coupon_code').val(), :action=>"apply_coupon_code" }, :method=>"post" %> ^formatted for easier reading Then inside my "apply_coupon_code" method I will go off to a couple other models and perform business logic before returning the updated invoice page. ...but maybe it's a pipe dream. I guess if push came to shove I could add the "coupon_code" field to my invoice model (even though it's persisted elsewhere.) so it's part of the entity and thus easily available on my form to send back into a controller, but I just hate adding a column to make a coupon validation easier. I figured I'd ping stackoverflow before taking that path.

    Read the article

  • Rails easy shop

    - by ciss
    I have some question about data organization in my shop. So, after easy mind hacking i decide to create three models: Item, Property and PropertyType Item: id,property_id Property: id, data, property_type_id #(data, serialized object with something like what: {:color => "red", :price => 1000} PropertyType: id, data #(data, also serialized object with {:color => :string, :price => :fixnum}) So, does this good or bad idea? I predict what I can find some problems with validations. But I really need some fields created by user via admin-panel (now I'm talking about Item Properties, which can be changed in any time)

    Read the article

  • Adding a LIKE criteria to a Rails Conditions block

    - by Neil Middleton
    Consider the following code which is to be thrown at an AR find: conditions = [] conditions[:age] = params[:age] if params[:age].present? conditions[:gender] = params[:gender] if params[:gender].present? I need to add another condition which is a LIKE criteria on a 'profile' attribute. How can I do this, as obviously a LIKE is usually done via an array, not a hash key.

    Read the article

  • Rails view - user enters minutes, we save seconds?

    - by sscirrus
    Hi everyone, I have a simple text_field in my form where a user enters a time in minutes, i.e. 60. How can I multiply that number by 60 before saving the form, such that the database stores the number in seconds? Then, how do I reverse that and show the field in minutes on another view? Thank you!

    Read the article

  • Rails Authlogic authentication method

    - by Rabbott
    Within Authlogic, is there a way that I can add conditions to the authentication method? I know by using the find_by_login_method I can specify another method to use, but when I use this I need to pass another parameter since the find_by_login_method method only passes the parameter that is deemed the 'login_field'. What I need to do is check something that is an association of the authentic model.. Here is the method I want to use # make sure that the user has access to the subdomain that they are # attempting to login to, subdomains are company names def self.find_by_email_and_company(email, company) user = User.find_by_email(email) companies = [] user.brands.each do |b| companies << b.company.id end user && companies.include?(company) end But this fails due to the fact that only one parameter is sent to the find_by_email_and_company method. The company is actually the subdomain, so in order to get it here I am just placing it in a hidden field in the form (only way I could think to get it to the model) Is there a method I can override somehow..?

    Read the article

  • Rails - Accessing Model Attributes in Forms

    - by stringo0
    Hi, How do I access a model's parent's attribute in a form? For example, for the following form for answer, I want to access answer.question.text and use that for the question - how do I do this? Thanks! <% form_for :answers do |ans| %> <%= ans.label :question, "Question" %> <%= ans.text_field :value %>

    Read the article

  • Rails log management

    - by ambertch
    I'm starting to get overwhelmed using VI to search through my logs to chase down login errors and would like a better solution. I know Newrelic is highly recommended, though was wondering if there was something free I could try for the short term. Thanks!

    Read the article

  • allow waiting user experience while file upload with rails and jquery

    - by poseid
    I am trying to display a waiting spinnger, while uploading a file. I am able to show the spinner, and to do the upload, when doing it individually. My problem is how to combine these two. The Jquery Javascript looks like: <% javascript_tag do %> function showLoading() { $("#loading").show(); } function hideLoading() { $("#loading").hide(); } function submitCallback() { showLoading(); $.post("create"); } <% end % My form looks like: <% semantic_form_for @face, :html => {:multipart => true} do |f| %> <%= f.error_messages %> <%= render 'fields', :f => f %> <p> <%= button_to_function 'create', "submitCallback()" %> </p> <% end %>

    Read the article

  • customized form_for tag in rails

    - by poseid
    I want to make a table within a form by making a new form_tag. The following code in ApplicationHelper fails: module ApplicationHelper class TabularFormBuilder < ActionView::Helpers::FormBuilder # ... code to insert <tr> tags </tr> end def tabular_form_for(name, object = nil, options = nil, &proc) concat("<table>", proc.binding) form_for(name, object, (options||{}).merge(:builder => TabularFormBuilder), &proc) concat("</table>", proc.binding) end end The view I use is: <h1>New project</h1> <% tabular_form_for :project, :builder => ApplicationHelper::TabularFormBuilder do |f| %> <%= f.error_messages %> <%= f.text_field :name %> <%= f.text_area :description %> <%= f.text_field :location %> <%= f.submit 'Create' %> <% end %> The error I get is: NoMethodError in Projects#new Showing app/views/projects/new.html.erb where line #5 raised: undefined method `errors' for {:builder=ApplicationHelper::TabularFormBuilder}:Hash Any ideas how to make this custom tag work?

    Read the article

  • Ruby on Rails: Modules vs. Classes

    - by Jack
    I'm trying to add a function that will be accessible throughout all parts of my program. I want something like: def GlobalFunctions.my_function(x,y) puts x + y end to be accessible for all models. Specifically I am trying to use a function like this in my seeds.rb file but I am most likely going to be reusing the code and don't want any redundancy. Now I know I can make a simple class, but I could also make a module. What are some reasons to go in either direction? And once I've decided on which type to use, how do I make it accessible throughout the whole program? I have tried a module, but I keep getting " Expected app/[module file] to define [ModuleName]"

    Read the article

  • call a Javascript function from controller more than once (in Rails)

    - by mm1
    hi. I have a multiple file upload form(html5) and want to update my view as soon one of the images is transfered to my image server. Currently I upload the files with ajax and use response_to_parent to update my upload view when all images are transfered to the image server. Is it possible to call a Javascript function from the controller more than once per action? def upload params[:images].each do |file| upload_to_image_server(file) #page << Update upload View end end Thanks, Michael

    Read the article

  • Validate format of email in rails.

    - by piemesons
    validates_format_of :email, :with => /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/, :message => "is missing or invalid" Please let me know where is the problem? Is regular expression is wrong?

    Read the article

  • Authorization in Rails

    - by sev
    Who can show me how I must use declarative_authorization (http://github.com/stffn/declarative_authorization) with restfult_authentication (http://github.com/technoweenie/restful-authentication)?

    Read the article

  • Is Spring hard compared to Ruby on Rails?

    - by johnny
    If I have no to little experience in either of them, but know enough Java and Ruby to be comfortable, is one framework harder to learn than the other? Is one easier to use for the beginner on these? I know it is hard to answer. Just looking for general thoughts on it.

    Read the article

  • Polymorphic associations in Rails

    - by Newy
    Say I have two models, Apples and Oranges, and they are both associated with a description in a Text model. Text is a separate class as I'd like to keep track of the different revisions. Is the following correct? Is there a better way to do this? [Apple] has_one :text, :as => :targit, :order => 'id DESC' has_many :revisions, :class_name => 'Text', :as => :targit, :order => 'id', :dependent => :destroy [Text] belongs_to :targit, :polymorphic => true

    Read the article

  • Rails saving data to model that has multiple has_many

    - by Ajey
    So I have a product model that looks like belongs_to :seller has_many :coupons And coupon model that looks like belongs_to :seller belongs_to :product And in my Products controller I use @seller = current_user @coupon = @seller.coupons.create(params[:coupon]) to create the coupons for the seller While the coupon is being created, I need to associate it with the product too, i.e When a new coupon is created it should be saved for the seller AS WELL AS for the product.

    Read the article

  • paperclipt get error can't dump File when upload video in rails

    - by user3510728
    when i try to upload video using paperclipt, i get error message can't dump File? model video : class Video < ActiveRecord::Base has_attached_file :avatar, :storage => :s3, :styles => { :mp4 => { :geometry => "640x480", :format => 'mp4' }, :thumb => { :geometry => "300x300>", :format => 'jpg', :time => 5 } }, :processors => [:ffmpeg] validates_attachment_presence :avatar validates_attachment_content_type :avatar, :content_type => /video/, :message => "Video not supported" end when i try to create video, im get this error?

    Read the article

  • Rails: Serializing objects in a database?

    - by keruilin
    I'm looking for some general guidance on serializing objects in a database. What are serialized objects? What are some best-practice scenarios for serializing objects in a DB? What attributes do you use when creating the column in the DB so you can use a serialized object? How to save a serialized object? And how to access the serialized object and its attributes? (Using hashes?)

    Read the article

  • Rails 3 Order By Count on has_many :through

    - by goo
    I have an application where I can list Items and add tags to each Item. The models Items and Tags are associated like this: class Item < ActiveRecord::Base has_many :taggings has_many :tags, :through => :taggings end class Tagging < ActiveRecord::Base belongs_to :item belongs_to :tag end class Tag < ActiveRecord::Base has_many :taggings has_many :items, :through => :taggings end So, this many-to-many relationship allows me to set n tags for each Item, and the same tag can be used several times. I'd like to list all tags ordered by the number of items associated with this tag. More used tags, shows first. Less used, last. How can I do that? Regards.

    Read the article

< Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >