Search Results

Search found 2 results on 1 pages for 'pmanning'.

Page 1/1 | 1 

  • Rails Association issue with NoMethodError in event_controller

    - by pmanning
    Kinda a noob trying to understand I think I need to define rsvps but not sure what to put... I'm trying to add a Join/Unjoin button to user created Events, similar to a Follow/Unfollow button for Users. NoMethodError in Events#show undefined method `model_name' for NilClass:Class in line #1 _unjoin.html.erb 1: <%= form_for(current_user.rsvps.find_by_joined_id(@event), 2: html: { method: :delete }) do |f| %> 3: <%= f.submit "Leave", class: "btn btn-large" %> 4: <% end %> events_controller.rb def show @event = Event.find(params[:id]) @user = current_user end Here's the models rsvp.rb class Rsvp < ActiveRecord::Base attr_accessible :joined_id belongs_to :joiner, class_name: "User" belongs_to :joined, class_name: "User" validates :joiner_id, presence: true validates :joined_id, presence: true end user.rb has_many :rsvps, foreign_key: "joiner_id", dependent: :destroy has_many :joined_events, through: :rsvps, source: :joined has_many :reverse_rsvps, foreign_key: "joined_id", class_name: "Rsvp", dependent: :destroy has_many :joiners, through: :reverse_rsvps, source: :joiner event.rb belongs_to :user has_many :rsvps, foreign_key: "joiner_id", dependent: :destroy has_many :joined_events, through: :rsvps, source: :joined has_many :reverse_rsvps, foreign_key: "joined_id", class_name: "Rsvp", dependent: :destroy has_many :joiners, through: :reverse_rsvps, source: :joiner

    Read the article

  • Rails Form Submission, User can't be blank

    - by pmanning
    I'm trying to create an event through an event form and I keep getting a form error that says "User can't be blank". The event needs a user_id to post a feed_item showing who created the event. Why can't this event get created? event.rb class Event < ActiveRecord::Base attr_accessible :description, :location, :title, :category_id, :start_date, :start_time, :end_date, :end_time, :image belongs_to :user belongs_to :category has_many :rsvps has_many :users, through: :rsvps, dependent: :destroy mount_uploader :image, ImageUploader validates :title, presence: true, length: { maximum: 60 } validates :user_id, presence: true create_events.rb (database) class CreateEvents < ActiveRecord::Migration def change create_table :events do |t| t.string :title t.date :start_date t.time :start_time t.date :end_date t.time :end_time t.string :location t.string :description t.integer :category_id t.integer :user_id t.timestamps end add_index :events, [:user_id, :created_at] end end events_controller.rb def new @event = Event.new @user = current_user end def create @event = current_user.events.build(params[:event]) if @event.save flash[:success] = "Sesh created!" redirect_to root_url else @feed_items = [] render 'static_pages/home' end end routes.rb SampleApp::Application.routes.draw do resources :users do member do get :following, :followers, :events end end resources :events do member do get :members end end root to: 'static_pages#home' events/new.html.erb <%= form_for @event, :html => {:multipart => true} do |f| %> <%= render 'shared/error_messages', object: @event %>

    Read the article

1