The Remove Avatar checkbox isn't doing anything for me on my edit form. Here is my code.
_form.html.erb
<%= simple_form_for(#child, html: { multipart: true}) do |f| %>
<% if child.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(child.errors.count, "error") %> prohibited this child from being saved:</h2>
<ul>
<% child.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :name %><br />
<div class="field"><%= f.text_field(:name) %> <br /></div>
<%= f.label :balance %><br />
<div class="field"> <%= f.text_field(:balance) %> <br /></div>
<%= f.label :parent_id %><b> ID</b><br />
<%= f.number_field :parent_id, :value => current_parent.id, :readonly => true %><br />
<%=f.label :avatar %><br />
<%= image_tag(#child.avatar_url) if #child.avatar? %>
<%= f.file_field(:avatar) %>
<%= f.hidden_field(:avatar_cache) %>
<br />
<label>
<%= f.check_box :remove_avatar %>
Remove Avatar
</label>
<div class="actions">
<% if #child.new_record? == true %>
<%= f.submit("Add Child") %>
<% else %>
<%= f.submit("Save Child") %>
<% end %>
</div>
<% end %>
Child Controller
class ChildrenController < ApplicationController
before_filter :authenticate_parent!
before_action :set_child, only: [:show, :edit, :update, :destroy]
# GET /children
# GET /children.json
def index
#children = Child.all
end
# GET /children/1
# GET /children/1.json
def show
end
# GET /children/new
def new
#child = Child.new
end
# GET /children/1/edit
def edit
end
# POST /children
# POST /children.json
def create
#child = Child.new(child_params)
if #child.avatar.file.nil?
img = LetterAvatar.generate(#child.name, 200)
File.open(img) do |f|
#child.avatar = f
end
end
respond_to do |format|
if #child.save
format.html { redirect_to #child, notice: 'Child was successfully created.' }
format.json { render :show, status: :created, location: #child }
else
format.html { render :new }
format.json { render json: #child.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /children/1
# PATCH/PUT /children/1.json
def update
if #child.avatar.file.nil?
img = LetterAvatar.generate(#child.name, 200)
File.open(img) do |f|
#child.avatar = f
end
end
respond_to do |format|
if #child.update(child_params)
format.html { redirect_to #child, notice: 'Child was successfully updated.' }
format.json { render :show, status: :ok, location: #child }
else
format.html { render :edit }
format.json { render json: #child.errors, status: :unprocessable_entity }
end
end
end
# DELETE /children/1
# DELETE /children/1.json
def destroy
#child.destroy
respond_to do |format|
format.html { redirect_to children_url, notice: 'Child was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_child
#child = Child.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def child_params
params.fetch(:child, {}).permit(:name, :balance, :parent_id, :avatar)
# params.fetch(:user, {}).permit(:first_name, :last_name, :email, :phone,
end
end
If I click save with the Remove Avatar box checked, it literally does nothing to the avatar, if I go back to any page that displayed the avatar, it is still there. What am I doing wrong? I am using Ruby on Rails 5.0.1
Side note: I am aware of some of the deprecated things that are being used here, such as before_filter. I am working with a large group of people so not all of this code is mine, fixing it is not priority at the moment.
Related
I'm trying to create an app, where a practitioner can add opening days and hours. The problem right now is, that when I hit the save button, it only creates one record. It should be creating a record for every day of the week.
So it would be
monday: open 9.00 - close 17.00
tuesday: open 8.30 - close 16.30
etc.
_form.html.erb
<script type="text/javascript">
$(document).ready(function () {
$('input:checkbox').bootstrapSwitch();
});
</script>
<%= #schedule.errors.full_messages %>
<%= simple_form_for([:clinic, :practitioner, #schedule]) do |f| %>
<table id="modal">
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<% Schedule.days.each do |day| %>
<tbody>
<tr>
<td id="modal-column-left" style="background-color:#aaa;">
<p>Åbningstider</p>
</td>
<td id="modal-column-right" style="background-color:#bbb;">
<p>Åbent/lukket</p>
</td>
</tr>
<tr>
<td id="modal-column-left" style="background-color:#aaa;">
<h2 style="margin-bottom: 5%;">
<h2 style="margin-bottom: 5%;"><%= day.titleize %>: <%= Date.today.send(day) %></h2>
<%= f.check_box :open_or_not, :data => { :size=>'small', 'on-color'=>'success', 'on-text'=>'YES', 'off-text'=>'NO' } %>
</td>
<td id="modal-column-right" style="background-color:#bbb;"><%= f.input :open_time %> <%= f.input :close_time %>
</td>
</tr>
</tbody>
<% end %>
</table>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
schedules_controller.rb
class SchedulesController < ApplicationController
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
# GET /schedules
# GET /schedules.json
def index
#schedules = Schedule.all
end
# GET /schedules/1
# GET /schedules/1.json
def show
end
# GET /schedules/new
def new
#schedule = Schedule.new
#schedules = Schedule.all
end
# GET /schedules/1/edit
def edit
end
# POST /schedules
# POST /schedules.json
def create
#schedule = Schedule.new(schedule_params)
respond_to do |format|
if #schedule.save
format.html { redirect_to clinic_practitioner_schedule_path(id: #schedule.id), notice: 'Schedule was successfully created.' }
format.json { render :show, status: :created, location: #schedule }
else
format.html { render :new }
format.json { render json: #schedule.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /schedules/1
# PATCH/PUT /schedules/1.json
def update
respond_to do |format|
if #schedule.update(schedule_params)
format.html { redirect_to clinic_practitioner_schedule_path(#schedule), notice: 'Schedule was successfully updated.' }
format.json { render :show, status: :ok, location: #schedule }
else
format.html { render :edit }
format.json { render json: #schedule.errors, status: :unprocessable_entity }
end
end
end
# DELETE /schedules/1
# DELETE /schedules/1.json
def destroy
#schedule.destroy
respond_to do |format|
format.html { redirect_to clinic_practitioner_schedules_url, notice: 'Schedule was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_schedule
#schedule = Schedule.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def schedule_params
params.require(:schedule).permit(:title, :start, :end, :practitioner_id, :account_id, :open_or_not, :day_of_week, :open_time, :close_time)
end
end
Read the documentation of complex forms.
You will want to attach multiple schedules to the Practitioner:
class Practitioner < ApplicationRecord
has_many :schedules
accepts_nested_attributes_for :schedules
end
The Controller
def practitioner_params
params.require(:practitioner).permit(:name, schedule_attributes: [:id, :open_or_not, :day_of_week, :open_time, :close_time])
end
And in the form:
<%= simple_form_for #practitioner do |f| %>
<%= f.input :name %>
<%= f.simple_fields_for :schedules do |s| %>
<%= s.input :open_or_not %>
<%= s.input :day_of_week %>
<%= s.input :open_time %>
<%= s.input :close_time %>
<% end %>
<% end %>
To dynamically add rows use the Cocoon gem.
I have a Ruby on Rails app that handles a users income, decides if it is an allowance or an income and applies the appropriate tax rates. I have included some enums to do basic functions as outlined below.
When I go to update from the default I hit the issue '1' is not a valid incomeType.
Below you can see the set up including model, controller and form.
model :
class Income < ApplicationRecord
enum incomeType: {income: 0, allowance: 1 }
enum taxed: {yes: 0, no: 1 }
belongs_to :user
end
controller:
class IncomesController < ApplicationController
before_action :set_income, only: [:show, :edit, :update, :destroy]
# GET /incomes
# GET /incomes.json
def index
#incomes = current_user.incomes.all
end
# GET /incomes/1
# GET /incomes/1.json
def show
end
# GET /incomes/new
def new
#income = current_user.incomes.build
end
# GET /incomes/1/edit
def edit
end
# POST /incomes
# POST /incomes.json
def create
#income = current_user.incomes.new(income_params)
respond_to do |format|
if #income.save
format.html { redirect_to #income, notice: 'Income was successfully created.' }
format.json { render :show, status: :created, location: #income }
else
format.html { render :new }
format.json { render json: #income.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /incomes/1
# PATCH/PUT /incomes/1.json
def update
respond_to do |format|
if #income.update(income_params)
format.html { redirect_to #income, notice: 'Income was successfully updated.' }
format.json { render :show, status: :ok, location: #income }
else
format.html { render :edit }
format.json { render json: #income.errors, status: :unprocessable_entity }
end
end
end
# DELETE /incomes/1
# DELETE /incomes/1.json
def destroy
#income.destroy
respond_to do |format|
format.html { redirect_to incomes_url, notice: 'Income was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_income
#income = Income.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def income_params
params.require(:income).permit(:amount, :frequency, :user_id, :incomeType, :country, :taxed)
end
end
Form :
<%= form_with(model: income, local: true) do |form| %>
<% if income.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(income.errors.count, "error") %> prohibited this income from being saved:</h2>
<ul>
<% income.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :amount %>
<%= form.text_field :amount, id: :income_amount %>
</div>
<div class="field">
<%= form.label :frequency %>
<%= form.select :frequency, options_for_select([['Weekly', '52'], ['Fortnightly', '26'], ['Monthly', '12'], ['Bi-Monthly', '6'], ['Annually', '1']]), id: :income_frequency %>
</div>
<div class="field">
<%= form.label :incomeType %>
<%= form.select :incomeType, options_for_select([['Income', '0'], ['Allowance', '1']]), id: :incomeType %>
</div>
<div class="field">
<%= form.label :taxed %>
<%= form.select :taxed, options_for_select([['Yes', '0'], ['No', '1']]), id: :taxed %>ra
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Hopefully you can point me in the right direct.
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"HUTd5Bav9eAfWPTFFyqeD69aL4mIgZodIuL1+9eL0zIhN+SjDwAMcD7AzKEuhm6az4iALBSrDUXd/1vVfN77SQ==",
"income"=>{"amount"=>"102000.0", "frequency"=>"1", "incomeType"=>"0", "taxed"=>"1"},
"commit"=>"Update Income",
"id"=>"4f9fc439-4578-487e-bc5d-02cf0cd9aaa3"}
Thanks in advance for your help
Yes it is because enum needs key not the value and you are sending value not the key so in your case enum is trying to find '0' as one key which is not present. So just change your form slightly
<%= form.select :incomeType, options_for_select([['Income', 'income'], ['Allowance', 'allowance']]), id: :incomeType %>
PS : change form for taxed as well.
Hope this will help
I am new in rails and I'm trying to make a form to associate roles with users, I have two collection_select in the form but when I want to create or update I get this error:
my controller code is :
class UserRolesController < ApplicationController
before_action :set_user_role, only: [:show, :edit, :update, :destroy]
##roles =RolesController.new
##users =UsersController.new
# GET /user_roles
# GET /user_roles.json
def index
#user_roles = UserRole.all
end
# GET /user_roles/1
# GET /user_roles/1.json
def show
end
# GET /user_roles/new
def new
#user_role = UserRole.new
#users =##users.get_all_users
#roles =##roles.get_all_roles
end
# GET /user_roles/1/edit
def edit
#users =##users.get_all_users
#roles =##roles.get_all_roles
#user_roles =UserRole.find(params[:id])
#selected_role=#user_roles.role_id
#selected_user=#user_roles.user_id
end
# POST /user_roles
# POST /user_roles.json
def create
#user_role = UserRole.new(user_role_params)
respond_to do |format|
if #user_role.save
format.html { redirect_to #user_role, notice: 'User role was successfully created.' }
format.json { render :show, status: :created, location: #user_role }
else
format.html { render :new }
format.json { render json: #user_role.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /user_roles/1
# PATCH/PUT /user_roles/1.json
def update
respond_to do |format|
if #user_role.update(user_role_params)
format.html { redirect_to #user_role, notice: 'User role was successfully updated.' }
format.json { render :show, status: :ok, location: #user_role }
else
format.html { render :edit }
format.json { render json: #user_role.errors, status: :unprocessable_entity }
end
end
end
# DELETE /user_roles/1
# DELETE /user_roles/1.json
def destroy
#user_role.destroy
respond_to do |format|
format.html { redirect_to user_roles_url, notice: 'User role was successfully destroyed.' }
format.json { head :no_content }
end
end
def get_user_role_by_userid(user_id)
return UserRole.where(user_id:user_id).first
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user_role
#user_role = UserRole.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_role_params
params.require(:user_role).permit(:role_id,:user_id)
end
end
My form code is :
<%= form_for(user_role) do |f| %>
<% if user_role.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user_role.errors.count, "error") %> prohibited this user_role from being saved:</h2>
<ul>
<% user_role.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user %>
<%= collection_select(:user_id, :user_id,#users, :id, :name,{:selected => #selected_user}) %>
</div>
<div class="field">
<%= f.label :rol %>
<%= collection_select(:role_id, :role_id,#roles, :id, :role {:selected => #selected_role}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
What i am doing wrong? , how i have to set the user_role_params in this case?
I am using ruby 2.3.1 and Rails : 5.0.1
Thanks for your suggestions.
You need to put an f before collection set like this:
<%= form_for(user_role) do |f| %>
<% if user_role.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user_role.errors.count, "error") %> prohibited this user_role from being saved:</h2>
<ul>
<% user_role.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user %>
<%= f.collection_select(:user_id, #users, :id, :name,{:selected => #selected_user}) %>
</div>
<div class="field">
<%= f.label :rol %>
<%= f.collection_select(:role_id, #roles, :id, :role {:selected => #selected_role}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
otherwise the params are being sent like user_id instead of user_role[user_id]
I have a landlord and landlord_address model. When a new landlord_address is created, the landlord_id is saved to the table. For some reason, when I edit a landlord_address the landlord_id is changed to NULL.
Models:
class Landlord < ActiveRecord::Base
has_many :landlord_addresses, dependent: :destroy
belongs_to :listing_agent, class_name: 'Agent'
end
class LandlordAddress < ActiveRecord::Base
belongs_to :landlord
has_many :landlord_companies, dependent: :destroy
end
Landlord Addresses Controller:
module Matrix
class LandlordAddressesController < ApplicationController
before_action :set_landlord_address, only: [:show, :edit, :update, :destroy]
# GET /landlord_addresses
# GET /landlord_addresses.json
def index
#landlord = Landlord.find(params[:landlord_id])
#landlord_addresses = #landlord.landlord_addresses.order(address_line_one: :asc)
end
# GET /landlord_addresses/1
# GET /landlord_addresses/1.json
def show
end
# GET /landlord_addresses/new
def new
#landlord_address = LandlordAddress.new
#landlord = Landlord.find(params[:landlord_id])
end
# GET /landlord_addresses/1/edit
def edit
end
# POST /landlord_addresses
# POST /landlord_addresses.json
def create
#landlord_address = LandlordAddress.new(landlord_address_params)
respond_to do |format|
if #landlord_address.save
format.html { redirect_to matrix_landlord_landlord_addresses_path, notice: 'Landlord address was successfully created.' }
format.json { render :show, status: :created, location: #landlord_address }
else
format.html { render :new }
format.json { render json: #landlord_address.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /landlord_addresses/1
# PATCH/PUT /landlord_addresses/1.json
def update
respond_to do |format|
if #landlord_address.update(landlord_address_params)
format.html { redirect_to matrix_landlord_landlord_addresses_path, notice: 'Landlord address was successfully updated.' }
format.json { render :show, status: :ok, location: #landlord_address }
else
format.html { render :edit }
format.json { render json: #landlord_address.errors, status: :unprocessable_entity }
end
end
end
# DELETE /landlord_addresses/1
# DELETE /landlord_addresses/1.json
def destroy
#landlord_address.destroy
respond_to do |format|
format.html { redirect_to landlord_addresses_url, notice: 'Landlord address was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_landlord_address
#landlord_address = LandlordAddress.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def landlord_address_params
params.require(:landlord_address).permit(:address_line_one, :address_line_two, :city, :state, :zip, :super_name, :super_number, :landlord_id, :latitude, :longitude)
end
end
end
Landlord Addresses _form:
<div class="feedback-container">
<%= form_for [:matrix, #landlord_address] do |f| %>
<% if #landlord_address.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#landlord_address.errors.count, "error") %> prohibited this landlord_address from being saved:</h2>
<ul>
<% #landlord_address.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
/ul>
</div>
<% end %>
<div id="form-map"></div>
<input id="pac-input" class="controls" type="text"
placeholder="Enter a location">
<div id="type-selector" class="controls">
<input type="radio" name="type" id="changetype-all" checked="checked">
<label for="changetype-all">All</label>
</div>
<div class="field">
<%= f.label :address, class: "general-text-label" %>
<%= f.text_field :address_line_one, class: "general-text-field map-autocomplete-address" %>
<%= f.hidden_field :latitude, class: "map-autocomplete-latitude" %>
<%= f.hidden_field :longitude, class: "map-autocomplete-longitude" %>
</div>
<div class="field">
<%= f.label :super_name, class: "general-text-label" %><br>
<%= f.text_field :super_name, class: "general-text-field" %>
</div>
<div class="field">
<%= f.label :super_number, class: "general-text-label" %><br>
<%= f.text_field :super_number, class: "general-text-field" %>
</div>
<div class="field">
<%= f.hidden_field :landlord_id, :value => params[:landlord_id] %>
</div><br>
<div class="actions">
<%= f.submit "Submit", class: "btn btn-black btn-4x" %>
</div>
<% end %>
</div>
Routes:
namespace :matrix do
resources :landlords, shallow: true do
resources :landlord_addresses do
resources :landlord_companies
end
end
end
New Error:
This part
<%= f.hidden_field :landlord_id, :value => params[:landlord_id] %>
will be your issue. When params[:landlord_id] is nil your record will be updated to null.
You should change it to
<%= f.hidden_field :landlord_id, :value => #landlord_address.landlord_id || #landlord.id %>
or some thing else.
Your route is nested, You dnt need to assign in hidden field. You can do it in the controller, passing params.
Form:
Remove hidden field, we are assigning it in the controller!
<div class="field">
<%= f.hidden_field :landlord_id, :value => params[:landlord_id] %>
</div><br>
Controller:
# POST /landlord_addresses
# POST /landlord_addresses.json
def create
#landlord_address = LandlordAddress.new(landlord_address_params)
# add this line here!
#landlord_address.landlord_id = params[:landlord_id]
respond_to do |format|
if #landlord_address.save
format.html { redirect_to matrix_landlord_landlord_addresses_path, notice: 'Landlord address was successfully created.' }
format.json { render :show, status: :created, location: #landlord_address }
else
format.html { render :new }
format.json { render json: #landlord_address.errors, status: :unprocessable_entity }
end
end
end
private
#ALSO REMOVE `:landlord_id` from
def landlord_address_params
params.require(:landlord_address).permit(:address_line_one, :address_line_two, :city, :state, :zip, :super_name, :super_number, :latitude, :longitude)
end
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.