Undefined method `id' for nil:NilClass (Controller#create) - ruby-on-rails

NameError in CommentsController#create undefined method `id' for nil:NilClass
The error on the following line. I want to save in field user_id (comment table) id user, which authorized in current time:
update_column(:user_id, user.id)
Model
class Comment < ActiveRecord::Base
belongs_to :user
has_many :likes
after_save :update_comments
def update_comments
update_column(:user_id, user.id)
true
end
end
class User < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
has_secure_password
has_many :comments
end
Comments_controller.rb
def create
#user = User.all
#comment = Comment.all
#comment = Comment.new(comment_params)
respond_to do |format|
if #comment.save
format.html { redirect_to #comment, notice: 'Comment was successfully created.' }
format.json { render action: 'show', status: :created, location: #comment }
else
format.html { render action: 'new' }
format.json { render json: #comment.errors, status: :unprocessable_entity }
end
end
end
**view/_form**
<%= simple_form_for(#comment) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :text %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
sessions/new
<%= form_tag do %>
<div class="as"><% if flash[:alert] %>
<p id="notice"><%= flash[:alert] %></p>
<% end %></div>
<br><br>
<fieldset>
<legend></legend>
<dl>
<dt><label for="email">Log in:</label></dt>
<dd><%= text_field_tag :name, params[:name], class: "user" %></dd>
</dl>
<dl>
<dt><label for="password">Password:</label></dt>
<dd><%= password_field_tag :password, params[:password], class: "password" %></dd>
</dl>
</fieldset>
<fieldset class="action">
<input type="submit" name="submit" id="submit" value="Enter" />
</fieldset>
<% end %>

Try using
def create
#user = User.all
#comment = Comment.all
#comment = #current_user.comments.new(comment_params)
respond_to do |format|
if #comment.save
format.html { redirect_to #comment, notice: 'Comment was successfully created.' }
format.json { render action: 'show', status: :created, location: #comment }
else
format.html { render action: 'new' }
format.json { render json: #comment.errors, status: :unprocessable_entity }
end
end
end
Then you need not to explicitly assign user_id to comment after_create. Using association it will automaticlly assign the user_id to the comment.

Related

What's wrong with association with user and emergency contact?

I am working on authentication part. Also, I am new to rails view part.
Here, I am trying to signup with required field but I am getting error message which is due to association between user and emergency contact. Can anyone suggest how to resolve it? Thanks in advance.
user.rb
class User < ApplicationRecord
has_one :emergency_contact, foreign_key: 'user_id'
end
emergency_contact.rb
class EmergencyContact < ApplicationRecord
belongs_to :user
end
registrations/new.html.erb
<h2>Sign up form</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="field">
<%= f.label :password %>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
<h3>Emergency Contact</h3>
<div>
<%= f.fields_for :emergency_contact, EmergencyContact.new do |emergency_contact| %>
<div>
<%= emergency_contact.label :full_name %> <br />
<%= emergency_contact.text_field :er_full_name %> <br />
</div>
<% end %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
users_controller.rb
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
#users = User.all
end
def show
end
def new
#user = User.new
end
def edit
end
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
format.html { redirect_to #user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: #user }
else
format.html { render :new }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #user.update(user_params)
format.html { redirect_to #user, notice: 'User was successfully updated.' }
format.json { render :show, status: :ok, location: #user }
else
format.html { render :edit }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
def destroy
#user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_user
#user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:email, :password,emergency_contact_attributes: [:er_full_name] )
end
end
Error message:
1 error prohibited this user from being saved:
Emergency contact user must exist
controller:
def new
#user = User.new
#emergency_contact = #user.build_emergency_contact
end
view:
<%= form.fields_for #emergency_contact do |emergency_contact_fields| %>
<div>
<%= emergency_contact_fields.label :full_name %> <br />
<%= emergency_contact_fields.text_field :er_full_name %> <br />
</div>
<% end %>

Rails: One_to_one relationship and form_for sending format instead of ID and params

I'm pretty new to rails and I'm having a bit of a though time to register my employeur.
Here are my routes:
resources :users do
resource :prestataire
resource :employeur
end
I have a has_one relationship between my employeur and user resources:
class User < ActiveRecord::Base
has_one :prestataire
has_one :employeur
has_secure_password
end
class Employeur < ActiveRecord::Base
belongs_to :user
validates :siren, :societe, :code_postal, presence: true
end
And here's where I think the issue is:
<%= form_for [#user,#employeur], url: user_employeur_path(#user) do |f| %>
<% if #employeur.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#employeur.errors.count, "error") %> prohibited this employeur from being saved:</h2>
<ul>
<% #employeur.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :siren, 'Siren: ' %><br>
<%= f.text_field :siren %>
</div>
.
.
.
<div class="actions">
<%= f.submit %>
</div>
<% end %>
When I fill in this issue, I'm redirected to /users/193/employeur.84 and I get this error: Couldn't find Employeur without an ID
Those are the only two params that are send after the form, even though I've indicated :siren, :societe, :code_postal
{"user_id"=>"193",
"format"=>"84"}
I guess that this might also come from my Emmployeur controller:
class EmployeursController < ApplicationController
before_filter :set_user
def index
#employeurs = #user.employeur.all
end
def show
#employeur = Employeur.find(params[:id]) #This is where the error happens since no id is sent.
end
def new
#employeur = #user.build_employeur
end
def edit
#employeur = Employeur.find(params[:id])
end
def create
#employeur = #user.build_employeur(employeur_params)
respond_to do |format|
if #employeur.save
format.html { redirect_to [#user, #employeur], notice: 'Employeur was successfully created.' }
else
format.html { render action: 'new' }
format.json { render json: #employeur.errors, status: :unprocessable_entity }
end
end
end
def update
#employeur = Employeur.find(params[:id])
respond_to do |format|
if #employeur.update_attributes(employeur_params)
format.html { redirect_to [#user, #employeur], notice: 'Employeur was successfully created.' }
format.json { render action: 'show', status: :created, location: #employeur }
else
format.html { render action: 'new' }
format.json { render json: #employeur.errors, status: :unprocessable_entity }
end
end
end
def destroy
#employeur = Employeur.find(params[:id])
#employeur.destroy
respond_to do |format|
format.html { redirect_to #user }
format.json { head :no_content }
end
end
private
def set_user
#user = User.find(params[:user_id])
end
def employeur_params
params.require(:employeur).permit(:siren, :societe, :code_postal)
end
end
Any help would be more then welcome.
In order to give an example of singular and nested resource working, I'll add a little more of my code:
class Employeur < ActiveRecord::Base
model_name.instance_variable_set(:#route_key, 'employeur')
belongs_to :user
has_many :projets, as: :projetable
has_many :prestataires, through: :projets
has_many :offres, through: :projets
has_many :feedbacks, through: :projets
validates :siren, :societe, :code_postal, presence: true, uniqueness: true
validates :code_postal, presence: true
validates_associated :user
end
Here's mu User controller that leads me from the user form to the employeur once filled:
class UsersController < ApplicationController
#TODO index user doit être suprimé quand inutile pour dev
def index
#users = User.all
end
def show
#user = User.find(params[:id])
end
def new
#user = User.new
end
# GET /users/1/edit
def edit
#user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
if params[:commit] == 'Employeur'
format.html { redirect_to new_user_employeur_path(user_id: #user), notice: "Renseignez vos informations d'employeur" }
format.json { render action: 'show', status: :created, location: #user }
else
format.html { redirect_to new_user_prestataire_path(user_id: #user), notice: "Renseignez vos informations de prestataire" }
format.json { render action: 'show', status: :created, location: #user }
end
else
format.html { render action: 'new' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
#user = User.find(params[:id])
respond_to do |format|
if #user.update(user_params)
if params[:commit] == 'Prestataire'
format.html { redirect_to new_user_prestataire_path(user_id: #user), notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { redirect_to new_user_employeur_path(user_id: #user), notice: "User was successfully updated." }
format.json { head :no_content }
end
else
format.html { render action: 'edit' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
#user = User.find(params[:id])
#user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :surname, :forename, :civility, :phone)
end
end
And finally, my User form:
<%= form_for(#user) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :civility, 'Titre de civilité: ' %><br>
<%= f.text_field :civility %>
</div>
<div class="field">
<%= f.label :forename, 'Prénom: ' %><br>
<%= f.text_field :forename %>
</div>
<div class="field">
<%= f.label :surname, 'Nom de famille: ' %><br>
<%= f.text_field :surname %>
</div>
<div class="field">
<%= f.label :email, 'Email: ' %><br>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password, 'Mot de passe: ' %><br>
<%= f.password_field :password, size: 40 %>
</div>
<div class="field">
<%= f.label :password_confirmation, 'Confirmation de mot de passe: ' %><br>
<%= f.password_field :password_confirmation, size: 40 %>
</div>
<div class="field">
<%= f.label :phone, 'Numéro de téléphone: ' %><br>
<%= f.text_field :phone %>
</div>
<div class="actions">
<%= f.submit "Employeur" %>
<%= f.submit "Prestataire" %>
</div>
<% end %>
Hope this will help someone as much as it would have helped me. Cheers !
You are not passing in the #employeur to your nested route user_employeur_path. Try this on your form_for line:
user_employeur_path(#user, #employeur)
But you shouldn't have to specify url; this should work:
<%= form_for [#user,#employeur] do |f| %>
See creating paths and urls from objects.
You don't have your EmployeursController setup correctly. Since employeur is a singular resource, you cannot reference it by id. Instead you need to change your show action to this:
def show
#employeur = User.find(params[:user_id]).employeur
end
The reason is that user_employeur_path(#user) creates a path like /users/193/employeur where you can access the user id in the controller via params[:user_id]
Also, since employeur is a singular resource, there is no index action defined for it. You can remove the index action entirely from your controller.
For people like me who were desperate to find an example of nested and singular resource working, I post my controller corrected thanks to the help of Hamed:
class EmployeursController < ApplicationController
before_filter :set_user
def new
#employeur = #user.build_employeur
end
def show
#employeur = #user.employeur
end
def edit
#employeur = #user.employeur
end
def create
#employeur = #user.build_employeur(employeur_params)
respond_to do |format|
if #employeur.save
format.html { redirect_to [#user, #employeur], notice: 'Employeur was successfully created.' }
else
format.html { render action: 'new' }
format.json { render json: #employeur.errors, status: :unprocessable_entity }
end
end
end
def update
#employeur = #user.employeur
respond_to do |format|
if #employeur.update_attributes(employeur_params)
format.html { redirect_to [#user, #employeur], notice: 'Employeur was successfully created.' }
format.json { render action: 'show', status: :created, location: #employeur }
else
format.html { render action: 'new' }
format.json { render json: #employeur.errors, status: :unprocessable_entity }
end
end
end
def destroy
#employeur = #user.employeur
#employeur.destroy
respond_to do |format|
format.html { redirect_to root_path }
format.json { head :no_content }
end
end
private
def set_user
#user = User.find(params[:user_id])
end
def employeur_params
params.require(:employeur).permit(:siren, :societe, :code_postal)
end
end

undefined local variable or method `user' for #<UsersController:0x0000000570eef0>

I'm new to rails and I'm trying to create a form in two parts. First, you fill in the user form. Then you choose to become a prestataire or a employeur. And by clicking on the respective button, the user form will be saved, and you will be redirected either to the prestataire's form or the employeur's with the recently created user params.
Until now, I didn't manage to send the recently created user params, only saving and redirecting. But then I get this error in the prestataire_controller, since prestataire belong to user. The error is similar when I click on the employeur button:
undefined local variable or method 'user' for #<UsersController:0x0000000570eef0>
format.json { render action: 'show', status: :created, location: #user }
else
format.html { redirect_to new_user_prestataire_path(user_id: user), notice: "Renseignez vos informations de prestataire" } #This is sublined
format.json { render action: 'show', status: :created, location: #user }
end
Here is the code I've written so far:
User Form:
<%= form_for(#user) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :civility, 'Titre de civilité: ' %><br>
<%= f.text_field :civility %>
</div>
<div class="field">
<%= f.label :forename, 'Prénom: ' %><br>
<%= f.text_field :forename %>
</div>
<div class="field">
<%= f.label :surname, 'Nom de famille: ' %><br>
<%= f.text_field :surname %>
</div>
<div class="field">
<%= f.label :email, 'Email: ' %><br>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password, 'Mot de passe: ' %><br>
<%= f.password_field :password, size: 40 %>
</div>
<div class="field">
<%= f.label :password_confirmation, 'Confirmation de mot de passe: ' %><br>
<%= f.password_field :password_confirmation, size: 40 %>
</div>
<div class="field">
<%= f.label :phone, 'Numéro de téléphone: ' %><br>
<%= f.text_field :phone %>
</div>
<div class="actions">
<%= f.submit 'Employeur', name: 'employeur' %>
<%= f.submit 'Prestataire', name: 'prestataire' %>
</div>
<% end %>
User controller:
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
if params[:commit] == 'employeur'
format.html { redirect_to new_user_employeur_path, notice: "Renseignez vos informations d'employeur" }
format.json { render action: 'show', status: :created, location: #user }
else
format.html { redirect_to new_user_prestataire_path, notice: "Renseignez vos informations de prestataire" }
format.json { render action: 'show', status: :created, location: #user }
end
else
format.html { render action: 'new' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if #user.update(user_params)
if params[:commit] == 'employeur'
format.html { redirect_to new_user_employeur_path, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { redirect_to new_user_prestataire_path, notice: "User was successfully updated." }
format.json { head :no_content }
end
else
format.html { render action: 'edit' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :surname, :forename, :civility, :phone, :employeur)
end
User model:
class User < ActiveRecord::Base
has_one :prestataire
has_one :employeur
validates :email, presence: true, uniqueness: true
validates :password, :forename, :surname, :phone, :civility, presence: true
validates :password, confirmation: true
has_secure_password
end
Routes file:
Workplace::Application.routes.draw do
resources :users do
resources :prestataires
resources :employeurs
end
resources :projets do
resources :feedbacks
resources :offres
end
root 'projets#index'
I was thinking about adding an onclik option on the f.submit and adding an adequate method. But I read somewhere that f.submit was not the best option for this kind of request, but no other suggestion was made. Thanks in advance for your help.
As I said,the error is because it should be #user in this line of your create action
format.html { redirect_to new_user_prestataire_path(user_id: #user), notice: "Renseignez vos informations de prestataire" }
And also,you haven't initialized #user in your update action which may rise in another error in future.Add this line at the beginning of your update action
#user = User.find(params[:id])
You are not defining your #user object on update. Try:
def update
#user = User.find(params[:id])
respond_to do |format|
if #user.update(user_params)
if params[:commit] == 'employeur'
format.html { redirect_to new_user_employeur_path, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { redirect_to new_user_prestataire_path, notice: "User was successfully updated." }
format.json { head :no_content }
end
else
format.html { render action: 'edit' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end

Cannot access model method inside its controller in Rails

In my Rails app, I have a controller tickets_controller.rb and model ticket.rb. For creating a ticket I have the following form,
<%= form_for(#ticket) do |f| %>
<% if #ticket.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#ticket.errors.count, "error") %> prohibited this ticket from being saved:</h2>
<ul>
<% #ticket.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :ref_no, "Reference Number"%><br/>
<%= f.text_field :ref_no%><br />
<%= f.label :category, "Type of Request"%><br/>
<%= f.text_field :category_id %><br />
<%= f.label :issue, "Issue"%><br/>
<%= f.text_area :issue%><br />
<%= f.label :ticket_priority, "Priority level"%><br/>
<%= f.text_field :ticket_priority_id %><br />
<%= f.label :ticket_status, "Current Status"%><br/>
<%= f.text_field :ticket_status_id %><br />
<%= f.label :project, "Project"%><br/>
<%= f.text_field :project_id %><br />
<div class="actions">
<%= f.submit %>
</div>
<% end %>
I want to create a unique random reference number on the form_load (ticket/new), and it should be appended to Reference Number text field. While creating a new reference number, it should check the tickets table for duplication. So I have the following model,
ticket.rb
class Ticket < ActiveRecord::Base
attr_accessible :issue, :ticket_status_id, :ticket_priority_id, :ref_no, :category_id, :project_id
has_many :ticket_statuses , :through => :ticket_histories
has_one :ticket_priority
belongs_to :user
before_create :generate_token
protected
def generate_num
self.token = loop do
random_token = random(1000000000)
break random_token unless Ticket.exists?(:ref_no => random_token)
end
end
end
and
tickets_controller.rb
class TicketsController < ApplicationController
before_filter :authenticate_user!
#load_and_authorize_resource
def index
#tickets = Ticket.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => #tickets }
end
end
def show
#ticket = Ticket.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => #ticket }
end
end
def new
#ticket = Ticket.new
#ref_no = Ticket.generate_num
#categories = Category.all
#status = TicketStatus.first
#priorities = TicketPriority.all
respond_to do |format|
format.html # new.html.erb
format.json { render :json => #ticket }
end
end
def edit
#ticket = Ticket.find(params[:id])
end
def create
#ticket = Ticket.new(params[:ticket])
respond_to do |format|
if #ticket.save
format.html { redirect_to #ticket, :notice => 'Ticket was successfully created.' }
format.json { render :json => #ticket, :status => :created, :location => #ticket }
else
format.html { render :action => "new" }
format.json { render :json => #ticket.errors, :status => :unprocessable_entity }
end
end
end
def update
#ticket = Ticket.find(params[:id])
respond_to do |format|
if #ticket.update_attributes(params[:ticket])
format.html { redirect_to #ticket, :notice => 'Ticket was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => #ticket.errors, :status => :unprocessable_entity }
end
end
end
def destroy
#ticket = Ticket.find(params[:id])
#ticket.destroy
respond_to do |format|
format.html { redirect_to tickets_url }
format.json { head :no_content }
end
end
end
When I run my app, I am getting the following error. Can anyone help?
NoMethodError in TicketsController#new
undefined method `generate_num' for #<Class:0x7f5cdc1f21c0>
Rails.root: /home/local/Rajesh/ticket_system
Application Trace | Framework Trace | Full Trace
app/controllers/tickets_controller.rb:27:in `new'
Change your model method generate_num to self.generate_num.
def self.generate_num
token = loop do
random_token = random(1000000000)
break random_token unless Ticket.exists?(:ref_no => random_token)
end
end
You have defined and instance method and you are calling it using Class
Call method using object
#ticket.generate_num

undefined method `model_name' for NilClass:Class. The action 'create' could not be found for

When I go to http://localhost:3000/register_entries/new, I am getting this error: undefined method `model_name' for NilClass:Class
Below is my _checkoutform.html.erb. If I add this line <% #register_entry = RegisterEntry.new %> to the beginning of the controller then the form comes up but when I submit I get the following error The action 'create' could not be found for RegisterEntriesController:
<%= form_for (#register_entry) do |f| %>
<% if #register_entry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#register_entry.errors.count, "error") %> prohibited this register from being saved:</h2>
<ul>
<% #register_entry.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :publisher %>
<%= f.collection_select :publisher_id, Publisher.order(:name), :id, :name %>
</div>
<div class="field">
<%= f.label :territory %>
<%= f.collection_select :territory_id, Territory.order(:last_worked), :id, :number %>
</div>
<div class="field">
<%= f.label "Checkout Date" %>
<%= f.date_select :checkout %>
</div>
<!-- <div class="field">
<%= f.label :checkin %><br />
<%= f.date_select :checkin %>
</div> -->
<!-- <div class="field">
<%= f.label :notes %><br />
<%= f.text_field :notes %>
</div> -->
<div class="actions">
<%= f.submit "Checkout Territory" %>
</div>
<% end %>
Here is my register_entries_controller.rb:
class RegisterEntriesController < ApplicationController
# GET /RegisterEntries
# GET /RegisterEntries.json
before_filter :authenticate_user!
helper_method :sort_column, :sort_direction
private
def sort_column
#register_entry.column_names.include?(params[:sort]) ? params[:sort] : "checkout"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
end
def index
authorize! :index, #user, :message => 'Not authorized'
#register_entries = RegisterEntry.order(sort_column + ' ' + sort_direction) #pluralized #register_entry
respond_to do |format|
format.html # index.html.erb
format.json { render json: #register_entries }
end
end
# GET /RegisterEntries/1
# GET /RegisterEntries/1.json
def show
#register_entry = RegisterEntry.find(params[:id])
#publishers = Publisher.all
respond_to do |format|
format.html # show.html.erb
format.json { render json: #register_entry }
end
end
# GET /RegisterEntries/new
# GET /RegisterEntries/new.json
def new
#register_entry = RegisterEntry.new
authorize! :index, #user, :message => 'Not authorized'
respond_to do |format|
format.html # new.html.erb
format.json { render json: #register_entry }
end
end
# GET /RegisterEntries/1/edit
def edit
authorize! :index, #user, :message => 'Not authorized'
#register_entry = RegisterEntry.find(params[:id])
end
# POST /RegisterEntries
# POST /RegisterEntries.json
def create
authorize! :index, #user, :message => 'Not authorized'
#register_entry = RegisterEntry.new(params[:register_entry])
respond_to do |format|
if #register_entry.save
format.html { redirect_to #register_entry, notice: 'Register Entry was successfully created.' }
format.json { render json: #register_entry, status: :created, location: #register_entry }
else
format.html { render action: "new" }
format.json { render json: #register_entry.errors, status: :unprocessable_entity }
end
end
end
# PUT /RegisterEntries/1
# PUT /RegisterEntries/1.json
def update
authorize! :index, #user, :message => 'Not authorized'
#register_entry = RegisterEntry.find(params[:id])
respond_to do |format|
if #register_entry.update_attributes(params[:register_entry])
format.html { redirect_to #register_entry, notice: 'Register Entry was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #register_entry.errors, status: :unprocessable_entity }
end
end
end
# DELETE /RegisterEntries/1
# DELETE /RegisterEntries/1.json
def destroy
authorize! :index, #user, :message => 'Not authorized'
#register_entry = RegisterEntry.find(params[:id])
#register_entry.destroy
respond_to do |format|
format.html { redirect_to register_entries_url }
format.json { head :no_content }
end
end
end
Been fighting with this for a few hours. Any ideas?
You are making all of your controller action methods private which means they can't be called as actions. See the end of the Methods and Actions section of the ActionController Rails Guide.

Resources