Search Results

Search found 7350 results on 294 pages for 'rspec rails'.

Page 122/294 | < Previous Page | 118 119 120 121 122 123 124 125 126 127 128 129  | Next Page >

  • undefined method `model_name' for NilClass:Class - Rails application

    - by user1270259
    So I have seen other articles here on stack about this and a lot of the time people are not doing @post = post.new. I read some where to use the plural...?? any ways I am getting this error on my discussion code: Discussion Controller class DiscussionsController < ApplicationController def index @discussion = Discussion.new @discussions = Discussion.all end def create @discussion = Discussion.create(params[:discussion]) if @discussion.save redirect_to tasks_path, :flash => {:success => 'Created a new discussion'} else redirect_to tasks_path, :flash => {:error => 'Failed to create a discussion'} end end end Discussion Form <%= form_for @discussion do |f| %> <p><%= f.label :title %> <%= f.text_field :title %></p> <p><%= f.label :content %> <%= f.text_area :content %></p> <% end %> Discussion Routes resources :discussions do resources :comments end Now as far as I know I am doing this right, because I have a task form set up essentially the same way - but I have looked at my code for hours and have googled and tried other examples and now i see this: undefined method `model_name' for NilClass:Class Extracted source (around line #1): 1: <%= form_for @discussion do |f| %> 2: 3: <p><%= f.label :title %> 4: <%= f.text_field :title %></p> Which should mean that I am missing something from my controller.....is it as asilly as a spelling mistake? .

    Read the article

  • rails: Get a list of items tagged x AND y AND z

    - by egarcia
    I've got two models: item and tags. Both have a name attribute. I want to find items tagged with several tags. class Item < ActiveRecord::Base has_many :tags validates_presence_of :name end class Tag < ActiveRecord::Base belongs_to :item validates_presence_of :name end Given a list of tag ids, I can easily enough get the list of items tagged with one tag or the other: # Find the items tagged with one or more of the tags on tag_ids Item.all(:conditions => ['tags.id in (?)', tag_ids], :joins => :tags) If tag_ids is {1,4}, then I get all pictures tagged with 1, or 4, or both. I want to know now how to get the pictures that are tagged with both - 1 AND 4. I can't even imagine the SQL that is needed here.

    Read the article

  • Renaming table in rails

    - by Tommy
    I want to rename a table... (any table.) I tried this line of code: ActiveRecord::ConnectionAdapters::SchemaStatements.rename_table(old_name, new_name) Here's the weird thing. I know I got it working the first time, but now I get this error: undefined method `rename_table' for ActiveRecord::ConnectionAdapters::SchemaStatements:Module Was there something I need to set? Or am I going blind here.. Thanks!

    Read the article

  • Two part form in Rails

    - by samuel02
    I have some two nested resources, so that a Product can have many Bookings. On one page in a different controller I want to create a new booking and since it's a "general" booking I want a select menu to appear in a modal window where the user is able to pick one of the existing products and then go to the booking page. How can I do this? I have no problem setting up the modal and the "New booking" page is already there. What I need is a form that generates a list of existing products, picks the selected product id and then gets /products/:product_id/bookings/new . Any help appreciated! I realize my title does not describe my problem very good so better suggestions are highly welcome!

    Read the article

  • Where is the ActionPack Gemspec file in rails 2.3.5?

    - by chief
    https://rails.lighthouseapp.com/projects/8994/tickets/3685-actionpack-235-gem-declares-incompatibility-with-rack-110 I am attempting to get thin running with rails 2.3.5 and it seems I need to modify some of the source code. Unfortunately I can't seem to locate this actionpack-2.3.5.gemspec. It is in the directory for rails 3 but for 2.3.5 I don't see it.

    Read the article

  • Respond_with not working Rails 3

    - by MDM
    As no one can help me with my UJS ajax problem I am trying "respond_with", but I am getting this error: RuntimeError (In order to use respond_with, first you need to declare the formats your controller responds to in the class level) Yet I have declared it in my controller: class HomepagesController < ApplicationController respond_to :html, :xml, :js def index @homepages = Homepage.search(params[:search]) respond_with(@homepages) end Anyone has any ideas why.

    Read the article

  • Rails: link_to method

    - by SuperString
    I have something like this: <p> <b>Tags:</b> <%if @post.tags.count > 0%> <%= @post.tags.collect {|c| (link_to c.name, c)}.join(", ")%> <%else%> Does not have any tags. <%end%> </p> Which gives me Tags: <a href="/tags/1">Java</a>, <a href="/tags/2">CSS</a> Instead of Java and CSS links. What am I missing?

    Read the article

  • Modifying an inherited Rails association

    - by Chris Kilmer
    I have a Team class that inherits from a Group class. Both Team and Groups have memberships through the same association. However, I need to run a method after a Team memberships is added but not a Group. I currently have something like this: class Group < ActiveRecord::Base has_many :memberships, :class_name => 'Connection', :foreign_key => 'connectable_id', :as => :connectable, :dependent => :destroy end class Team < Group has_many :memberships, :class_name => 'Connection', :foreign_key => 'connectable_id', :as => :connectable, :dependent => :destroy, :after_add => :add_company_membership private def membership_check(membership) end end Is there some way to modify the inherited association in Team so that I don't have to redefine the entire thing but rather just add the :after_add hook it? Any help would be appreciated.

    Read the article

  • Rails nil can't be coerced into Float

    - by alex
    After adding items, attempting to view my cart leads me to this error: nil can't be coerced into Float with the math line in this method in my line_item model highlighted: def total_price product.price * quantity end line items create action def create product = Product.find(params[:product_id]) @line_item = @cart.add_product(product.id) @line_item.quantity = params[:quantity] view <div id= "text_field"><%= text_field_tag 'quantity' %> </div> <%= button_to 'Add to Cart', line_items_path(:product_id => product) %> This has held me back for a couple days. (I'm new). Thanks.

    Read the article

  • Rails delayed_job sending email as HTML

    - by mcmaloney
    Using delayed_job to send emails- files are filename.text.html.erb Sometimes they show up in my inbox rendered properly and sometimes they show up as HTML code. I notice that when I stop and start the delayed_job daemon on the server, it seems to help in some cases but not all the time. Any ideas?

    Read the article

  • Rails - how to serialize a tree not in a form

    - by tiny_clanger
    I started with the standard scriptaculous drag and drop tree, and that all works fine. Then started implementing this: http://www.artweb-design.de/2008/5/30/scriptaculous-sortabletree which gives a good drag and drop tree Where I am stuck is how to get serialize the tree (unordered list)? It's not in a form, and I can't find a way to serialize it to move onto setting up the AJAX update.

    Read the article

  • Rails - dynamically adding to sortable_element

    - by tiny_clanger
    Am adding to a sortable list using Ajax, and to get the Scriptaculous effects to kick in after the add, the only way I have found is by re-executing sortable_element. Can anyone suggest a better way of doing this, at the complete code is a hack: <%= link_to_remote "Add", :url = { :controller = "pages", :action = "add_fragment", :pid = pid, :index = index }, :complete = "eval(decodeURIComponent(#{sortable_element 'frag_list', :url = sort_frag_pages_path, :complete = visual_effect(:highlight, 'frag_list'), :handle = 'handle'}).gsub('//',''));" %

    Read the article

  • Block call in Ruby on Rails

    - by Mattias
    Hi, I'm trying to clean up my code and get rid of a lot of ugly hashes. In my views I define several actions like this: @actions = { :interest => {'Show interest', link_to(..), :disabled => true}, :follow => {'Follow this case', link_to(..)} ... } As these hashes grow, the maintainability decreases. I want to convert the above format to something like: actions do item :interest, 'Show interest', link_to(..), :disabled => true item :follow, 'Follow', link_to(..) ... end How do I structure my helper methods to allow this? Preferably the 'item'-method should only be available in the 'actions' block and not in the global scope. Thanks!

    Read the article

  • how to set custom tab in jquery ui and use with rails

    - by Katyal
    I'm using jqueryUI for tabs on a page. I initialize it like below: $("#tabs").tabs(); <div id="tabs"> <ul> <li><a href="#tabs-4">Part A</a></li> <li><a href="#tabs-2">Part B</a></li> <li><a href="#tabs-5">Part C</a></li> </ul> <div id="tabs-4"> ..... </div> <div id="tabs-2"> .... </div> <div id="tabs-5"> .... </div> </div> I have 2 questions. How do I set the tab to be custom. say I want second tab to be shown first. $('#tabs').tabs(2) does not work. i got that from this link Let say I click on a button inside tab1. Clicking on the button takes control back to an action and then control comes back to this page. When the control comes back...then is it possible to set a custom tab?. For example. in tab 1 I click something...go back to the action...and then I want to come back to tab 2.

    Read the article

  • Ruby on rails edit form for has_one relation

    - by user2900873
    I have a clan.rb and clan_options.rb clan.rb class Clan < ActiveRecord::Base has_one :options, :class_name => "ClanOptions", :foreign_key => "clan_id", dependent: :destroy end clan_options.rb class ClanOptions < ActiveRecord::Base belongs_to :clan end To create an edit form for clan.rb I use the following: <%= form_for @clan, :html => {:class => 'form-horizontal'} do |clan| %> <fieldset> <!-- form stuff --> </fieldset> <% end %> It works how I want. But now I want to create an edit form for the clan_options.rb, I have no idea how to do this. If anymore information is needed to solve this, ask me.

    Read the article

  • Ruby On Rails - Collection Select - MYSQL Database - Problem Displaying ampersand ("&")

    - by dbkbaki
    I am having an annoying problem displaying the labels of a select box correctly where there is an ampersand contained within the label string. On a form being rendered with the form_for helper the collection_select reads data from a Mysql 5.075 database the text stored in the database is "Surabaya & Surrounding Areas" when rendered and displayed in firefox 3.6 or safari is is displaying as "Surabaya %amp; Surrounding Areas". The code used to render the select is as follows: <%= f.collection_select :parent_id, Destination.roots, :id, :name, {:include_blank => true} %> I have tried adding a h(:name) and also storing && in the database but it still will not display the ampersand correctly. Have searched on google for what I thought would be a simple solution but cant find anything that solves this. Using ROR 2.3.5/Ruby 1.8.7 If anyone has a solution it will be much appreciated. many thanks, David

    Read the article

  • Return user to original page after logging in (rails session mgmt)

    - by keruilin
    I'm looking for some general guidance as to how to return a user back to the original page they were viewing after trying to log-in. The way I have the site setup now is that if a user visits the Store page, for example, and then clicks the login button in the upper right, the user is returned to the default landing page. Any help would be greatly appreciated!

    Read the article

  • Rails find through association

    - by yogi
    class Customer < ActiveRecord::Base has_one :address, :foreign_key => "customerid" end class Address < ActiveRecord::Base belongs_to :customer, :foreign_key => "customerid" end How do I find records in customer that do not have customerid in address table? in SQL i'd do select * from customer a, address b where a.customerid <> b.customerid

    Read the article

  • Rails - Searching multiple textboxes and fields

    - by ChrisWesAllen
    I have a model of events that has various information such as date, location, and description of whats going on. I would like for my users to be able to search through the events list through a set of different textboxes but I having a hard time getting the syntax just right in my view I have... <% form_tag users_path, :method => 'get' do %> (<%= text_field_tag :search_keyword, params[:search_keyword] %>) + (<%= text_field_tag :search_zip, params[:search_zip] %>) <%= submit_tag "Find Events!", :name => nil %> <% end %> and in the controller I'm trying to query through the results.... if params[:search_keyword] @events = Event.find(:all, :conditions => [' name LIKE ? ', "%#{params[:search_keyword]}%"]) elsif params[:search_zip] @events = Event.find(:all, :origin=> params[:search_zip], :within=>50 ) else @events = Event.find(:all) end How do I code it so that it will perform the search only if the textbox isnt empty? also if both textboxes are filled then @events should be the product of BOTH queries? if have no idea if this would work =(???@event = @event+ event.find.....???

    Read the article

  • Rails Nested Attributes Doesn't Insert ID Correctly

    - by MunkiPhD
    I'm attempting to edit a model's nested attributes, much as outline here, replicated here: <%= form_for @person do |person_form| %> <%= person_form.text_field :name %> <% for address in @person.addresses %> <%= person_form.fields_for address, :index => address do |address_form|%> <%= address_form.text_field :city %> <% end %> <% end %> <% end %> In my code, I have the following: <%= form_for(@meal) do |f| %> <!-- some other stuff that's irrelevant... --> <% for subitem in @meal.meal_line_items %> <%= f.fields_for subitem, :index => subitem do |line_item_form| %> <%= line_item_form.label :servings %><br/> <%= line_item_form.text_field :servings %><br/> <%= line_item_form.label :food_id %><br/> <%= line_item_form.text_field :food_id %><br/> <% end %> <% end %> <%= f.submit %> <% end %> This works great, except, when I look at the HTML, it's creating the inputs that look like the following, failing to input the correct id and instead placing the memory representation(?) of the model: <input type="text" value="2" size="30" name="meal[meal_line_item][#<MealLineItem:0x00000005c5d618>][servings]" id="meal_meal_line_item_#<MealLineItem:0x00000005c5d618>_servings">

    Read the article

  • Rails forms: render different actions based on validation

    - by Martin Petrov
    Is it possible to render different actions based on what fails at validation? For example - I have one field in the form - email addres. It is validated like this: validates :email, :presence => true, :uniqueness => { :case_sensitive => false } In the controller: def create @user = User.new(params[:user]) if @user.save redirect_to somewhere else # render :new if email is blank # redirect_to somwhere if email is taken end end

    Read the article

  • Routing error in rails

    - by user662503
    In my controller I have def update_project_dates p "It is end date....." @user=User.find(params[:user]) @projects=Project.find_all_by_user_id(@user) end In the view page (only some part of the code is copied and pasted) eventDrop: function() { $.ajax({ url:'/update_project_dates/', success:function(data) { alert("Hello"); } }) }, In my routes.rb I have mentioned match '/update_project_dates' => 'users#update_project_dates', :method=> :get get 'update_project_dates' But When the ajax request goes, I get the routing error as Routing Error uninitialized constant UsersController Where am I doing wrong here...Please help..

    Read the article

  • before_save not working with Rails 3

    - by Mich Dart
    I have this Project model: class Project < ActiveRecord::Base validates :status, :inclusion => { :in => ['active', 'closed'] } validates :title, :presence => true, :length => { :in => 4..30 } before_save :set_default_status_if_not_specified private def set_default_status_if_not_specified self.status = 'active' if self.status.blank? end end If I create a new object like this: Project.create!(:title => 'Test 2', :pm_id => 1) I get these errors: Validation failed: Status is not included in the list But status field should get filled in before save.

    Read the article

  • rails: self-referential association

    - by john
    hi, My needs are very simple: I have a Tip table to receive comments and have comments to receive comments, too. To retrieve each comment that is stored in the same table (comments), I created another key for the comments on comments: "inverse_comments". I tried to use one comments table by using self-referntial association. Some resources seem to bring more than one table into the piture which are diffent from my needs. So I came up whth the following modeling for comments: class Comment < ActiveRecord::Base belongs_to :tip belongs_to :user has_many :mycomments, :through => :inverse_comments, :source => :comment end Apparently something is missing here but I cannot figure it out. Could some one enlighten me on this: what changes I need to do to make the model work? thanks.

    Read the article

< Previous Page | 118 119 120 121 122 123 124 125 126 127 128 129  | Next Page >