Validate 2 models in 1 form - ruby

I'm learning RoR and I can't find a way to validate my models in the same form. It is validating, but it only shows the error messages of one model (address) and it's filling the other input fields of the other model like it was before the changes were made. I tried a few things but none of them worked.
In the edit.html.erb I'm showing the error messages. This works fine only if one model is not correct. If the input in both models are not correct, I only see the error message of address and the input fields of mutuality are reset with the previous values.
I think this is all you really need. My address controller is empty. Everything else is working fine except the validation.
Mathias.
Edit.html.erb:
<h1>Edit Mutuality</h1>
<%= form_for #mutuality do |f| %>
<%= fields_for #address do |fa| %>
<% if #mutuality.errors.any? %>
<h2>Errors:</h2>
<ul>
<% #mutuality.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<% if #address.errors.any? %>
<h2>Errors:</h2>
<ul>
<% #address.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<table>
<tr>
<td>
<%= f.label :name %>
</td>
<td>
<%= f.text_field :name %>
</td>
</tr>
<tr>
<td>
<%= f.label :phone %>
</td>
<td>
<%= f.text_field :phone %>
</td>
</tr>
<tr>
<td>
<%= f.label :contact %>
</td>
<td>
<%= f.text_field :contact %>
</td>
</tr>
<tr>
<td>
<%= fa.label :street %>
</td>
<td>
<%= fa.text_field :street %>
</td>
</tr>
<tr>
<td>
<%= fa.label :number %>
</td>
<td>
<%= fa.text_field :number %>
</td>
</tr>
<tr>
<td>
<%= fa.label :zipcode %>
</td>
<td>
<%= fa.text_field :zipcode %>
</td>
</tr>
<tr>
<td>
<%= fa.label :city %>
</td>
<td>
<%= fa.text_field :city %>
</td>
</tr>
<tr>
<td>
</td>
<td>
<%= f.submit %>
</td>
</tr>
</table>
<% end %>
Controller:
class MutualitiesController < ApplicationController
def index
#mutualities = Mutuality.all
end
def show
#mutuality = Mutuality.find(params[:id])
end
def new
#mutuality = Mutuality.new
#address = Address.new
end
def create
#mutuality = Mutuality.new(params[:mutuality])
#address = Address.new(params[:address])
if #address.save
#mutuality.address_id = #address.id
if #mutuality.save
redirect_to mutualities_path, :notice => "Mutuality saved with succes!"
else
render "new"
end
else
render "new"
end
end
def edit
#mutuality = Mutuality.find(params[:id])
#address = Address.find(#mutuality.address_id)
end
def update
#mutuality = Mutuality.find(params[:id])
#address = Address.find(#mutuality.address_id)
if #address.update_attributes(params[:address])
if #mutuality.update_attributes(params[:mutuality])
redirect_to mutualities_path, :notice => "Mutuality updated with succes!"
else
render "edit"
end
else
render "edit"
end
end
def destroy
#mutuality = Mutuality.find(params[:id])
#address = Address.find(#mutuality.address_id)
#mutuality.destroy
#address.destroy
redirect_to mutualities_path
end
end

Rails can handle nested-attributes automatically. You are doing it all manually.
Not sure if you have defined the associations in your model correctly.
So, in your model you should write:
class Mutuality
belongs_to :address
accepts_nested_attributes_for :address
end
and in your controller you can then just write:
def create
#mutuality = Mutuality.new(params[:mutuality])
if #mutuality.save
redirect_to mutualities_path, :notice => "Mutuality saved with succes!"
else
render "new"
end
end
HTH.

I finally managed to make the thing work! I made the changes that Nathanvda told me, but I had to add a few things to make it work. There's still one tiny problem. I can't manage to delete the address. It only deletes the Mutuality. Any ideas?
Address.rb
class Address < ActiveRecord::Base
#attr_accessible :street, :number, :zipcode, :city
attr_protected :id
has_one :mutuality
validates_presence_of :street, :number, :city
end
Mutuality.rb
class Mutuality < ActiveRecord::Base
#attr_accessible :name, :phone, :contact, :address_id
attr_protected :id, :address_id
belongs_to :address
accepts_nested_attributes_for :address, :allow_destroy => true
validates_presence_of :name, :phone, :contact
validates_length_of :name, :minimum => 5
validates_uniqueness_of :name
end
This is the link I use on the show.html.erb:
<p>
<%= link_to "Back", mutualities_path %> |
<%= link_to "Edit", edit_mutuality_path %> |
<%= link_to "Delete", #mutuality, :confirm => "You are going to delete " + #mutuality.name + ". Do you wish to continue?", :method => :delete %>
</p>
And here's the destroy function:
def destroy
#mutuality = Mutuality.find(params[:id])
if #mutuality.destroy
redirect_to mutualities_path, :notice => "Mutuality deleted with succes!"
else
redirect_to mutualities_path, :error => "A problem has occured."
end
end
Mathias

Related

How to use a checkbox to modify a value from each object of a model using a nested form

I'm new at programming and I have a question related to making a form in Ruby on Rails. I'm making a database for storing products' units. These units are, upon creation, initially located at the storage. This location is stored in a column Unit model. Then I have a model Store and a model Remission.
class Unit < ActiveRecord::Base
belongs_to :store
belongs_to :remission
attr_accessor :into_remission
end
class Remission < ActiveRecord::Base
belongs_to :store
has_many :units
accepts_nested_attributes_for :units
end
class Store < ActiveRecord::Base
has_many :units
has_many :remissions
end
Store has_many :remissions and Remission has_many :units. The idea is that when I put some units for selling in a store I have to create a remission. This remission is the list of products that I gave the store so we both can have a reference of which products are at the store. So I have a form to create a remission in which you can select the store that would change the store_id(reference) of the Remission. I also want to select from this same form the units that would take part in this new remission changing the remission_id(reference) from each unit. For that I made a attar_accessor :into_remissions in the Unit model so I could change that to true in each unit that would end up in the remission with a checkbox. I having a lot of problems making this work, here is the code of my form:
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#remission) do |f| %>
<%= render 'shared/error_messages_remissions' %>
#Here you select the store that would own the remission and the products
<div class="field">
<%= f.label :store_id, "Producto" %> <br/>
<%= f.collection_select :store_id, #stores.order(:name), :id, :name, prompt: "Select Store" %>
</div>
#Here its a dynamic table that display all the products in storage
<table id="products" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product Name</th>
<th>Remission</th>
</tr>
</thead>
<tbody>
#HERE I WANT TO MAKE A CHECK_BOX THAT CHANGES THE INTO_REMISSION VALUE FROM EACH UNIT. SO IT MARKS THE UNITS THAT WOULD TAKE PART IN THE REMISSION
<%= f.fields_for :units do |ff| %>
<% #units.each do |unit| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</div>
</div>
Needless to say he check_box its now showing nor working.
I not sure how to make this work and any advices would be welcome as I'm new with rails and programming. Thanks
Try changing this:
<%= f.fields_for :units do |ff| %>
<% #units.each do |unit| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
into this:
<% #units.each do |unit| %>
<%= f.fields_for :units, unit do |ff| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
I think you should first iterate over the units and pass each unit separately into the fields for. That should solve the showing issue.

Sinatra: NameError at '/route', undefined local variable or method

I'm trying to build an admin backend for a cms website.
this is the structure of my application
├── app.rb
├── Gemfile
├── models
│   └── models.rb
├── routes
│   └── routes.rb
└── views
├── categories.erb
├── # ... other view files
app.rb
require 'sinatra'
require 'data_mapper'
require 'dm-core'
require 'dm-migrations'
require 'digest'
enable :sessions
DataMapper.setup(:default, 'mysql://username:password#localhost/database')
require './models/models.rb'
require './routes/routes.rb'
DataMapper.finalize
models.rb
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :posts
end
# other model definitons
I've defined a categories route inside my routes.rb
...
get '/categories' do
#categories = Category.all
erb :categories
end
...
Contents of view (categories.erb) file.
#table headers
<tbody>
<% #categories.each do |c| %>
<tr>
<td>
<%= c.id %>
</td>
<td>
<%= c.name %>
</td>
<td>
<%= с.posts.count %>
</td>
<td>
<%= c.posts(:order => [:updated_at.desc]).first.updated_at.strftime("%d/%m/%Y") %>
</td>
</tr>
<% end %>
</tbody>
When I browse to /categories route, server spits this error
NameError at /categories
undefined local variable or method `с' for #<Sinatra::Application:0x0000000284bc08>
I have not faced such problem before. And really don't know what is going on.
The problem probably is not with application structure (the require sequences inside app.rb) because, before get '/categories' I've defined a post '/login' route which checks user inputs against database records. And it works as I want.
post '/login' do
email = params[:email]
pwd = params[:password]
user = Author.first(:email=>email)
if user.nil?
redirect to ('/register')
elsif !user.nil?
if Digest::MD5.hexdigest(pwd) == user.password
... #and so on
UPDATE
I'm listing other table/models with same methods, and all of them works as i expected, but categories.
other routes
get '/articles' do
#articles = Post.all(:is_blog_post => false)
erb :site_articles
end
##blog articles
get '/blogposts' do
#barticles = Post.all(:is_blog_post => true)
erb :blog_articles
end
#users
get '/admin_users' do
#admins = Author.all(:is_admin=>true)
erb :admin_users
end
#bloggers
get '/bloggers' do
#bloggers = Author.all(:is_admin=>false)
erb :blog_users
end
and corresponding view files
site articles
<tbody>
<% #articles.each do |art| %>
<tr>
<td>
<%= art.title %>
</td>
<td>
<%= art.author.full_name %>
</td>
<td>
<%= art.category.name %>
</td>
<td>
<%= art.updated_at.strftime("%d/%m/%Y %H:%M") %>
</td>
<td>
<%= art.featured? ? "Yes" : "No" %>
</td>
</tr>
<% end %>
</tbody>
blog articles
<tbody>
<% #barticles.each do |art| %>
<tr>
<td>
<%= art.title %>
</td>
<td>
<%= art.author.full_name %>
</td>
<td>
<%= art.category.name %>
</td>
<td>
<%= art.updated_at.strftime("%d/%m/%Y %H:%M") %>
</td>
<td>
<%= art.featured? ? "Yes" : "No" %>
</td>
</tr>
<% end %>
</tbody>
admins
<tbody>
<% #admins.each do |admin| %>
<tr>
<td>
<%= admin.full_name %>
</td>
<td>
<%= admin.email %>
</td>
<td>
<%= !admin.twitter.nil? ? admin.twitter : "N/A" %>
</td>
<td>
<%= !admin.facebook.nil? ? admin.facebook : "N/A" %>
</td>
<td>
<%= !admin.phone.nil? ? admin.phone : "N/A" %>
</td>
<td>
<%= admin.posts.count %>
</td>
</tr>
<% end %>
</tbody>
bloggers
<tbody>
<% #bloggers.each do |blogger| %>
<tr>
<td>
<%= blogger.full_name %>
</td>
<td>
<%= blogger.email %>
</td>
<td>
<%= !blogger.twitter.nil? ? blogger.twitter : "N/A" %>
</td>
<td>
<%= !blogger.facebook.nil? ? blogger.facebook : "N/A" %>
</td>
<td>
<%= !blogger.phone.nil? ? blogger.phone : "N/A" %>
</td>
<td>
<%= blogger.posts.count %>
</td>
</tr>
<% end %>
</tbody>
You’ve somehow got an odd character in your source. That’s not a “normal” latin c in the line <%= с.posts.count %>, it’s U+0441, CYRILLIC SMALL LETTER ES. It just looks like a latin c.
To fix it just delete the character and re-write it with a normal c.

How can I solve NoMethodError from from ROR?

Can anybody please help me to resolve the below error.
Error:
NoMethodError in Homes#managebooks
Showing C:/Site/library_management1/app/views/homes/managebooks.html.erb where line #48 raised:
undefined method `book_name' for #<Array:0x229d340>
Actually I want fetch all data to the existing table to display after submitting.When i clicked on submit button all the data saved into DB but after that it is throwing the above error.Please help to resolve those error very soon.
My codes are as follows.
views/homes/managebooks.html.erb
<% if admin_signed_in? %>
<div class="bar">
Logged in as <strong><%= current_admin.email %></strong>.
<%= link_to 'Edit profile', edit_admin_registration_path, :class => 'navbar-link' %> |
<%= link_to "Logout", destroy_admin_session_path, method: :delete, :class => 'navbar-link' %>
</div>
<% else %>
<%= link_to "Sign up", new_admin_registration_path, :class => 'navbar-link' %> |
<%= link_to "Login", new_admin_session_path, :class => 'navbar-link' %>
<% end %>
<div class="big-container">
<% if flash[:color]== "valid" %>
<div class="valid_notice">
<p><%= flash[:notice]%></p>
</div>
<% elsif flash[:color]== "invalid"%>
<div class="invalid_notice">
<p><%=flash[:notice]%></p>
</div>
<%else%>
<div class="notice">
<p><%=flash[:notice]%></p>
</div>
<%end%>
<div class="admin-image">
<div class="bpaddingdiv1"><img src="/assets/admin.png" border="0" name="admin" /></div>
</div>
<div class="borderlightgreen"></div>
<div class="admin-name">
<div class="tpaddingdiv2 textaligncenterdiv"><img src="/assets/adminpanel.png" border="0" name="admin" /></div>
</div>
<div class="leftside">
<div id="leftsidebtn">
<ul>
<li>Manage Books</li>
<li><a href="#" >Manage Pages</a></li>
<li><a href="#" >Manage Header Banner</a></li>
<li><a href="#" >Brand</a></li>
</ul>
</div>
</div>
<div class="middlebox">
<center>
<%= form_for :books,:url => {:action => "savebooks"} do |f| %>
<fieldset>
<p>
<label for="name">Book name</label>
<%= f.text_field :book_name,placeholder:"enter book name" %>
</p>
<p>
<label for="tel">Book title</label>
<%= f.text_field :book_title,placeholder:"enter book title" %>
</p>
<p>
<label for="email">Author Name</label>
<%= f.text_field :author_name,placeholder:"enter book author name" %>
</p>
<p>
<label for="password">publisher Name</label>
<%= f.text_field :publisher_name,placeholder:"enter book publisher name" %>
</p>
<p>
<label for="password"> Edition</label>
<%= f.text_field :edition,placeholder:"enter book edition" %>
</p>
<p>
<label for="password">Pages</label>
<%= f.text_field :pages,placeholder:"enter book pages" %>
</p>
<p>
<label for="password"> Date of pursase</label>
<%= f.date_select :date_of_purchase %>
</p>
<p>
<%= f.submit "SUBMIT" %>
</p>
</fieldset>
<% end %>
</center>
<% if params[:id] %>
<table>
<tr>
<th>Book name</th>
<th>Book title</th>
<th>Author Name</th>
<th>publisher Name </th>
<th>Edition</th>
<th>Pages</th>
<th>Date of pursase</th>
<th>Status</th>
<th>Action</th>
</tr>
<tr>
<td><%= #books.book_name %></td>
<td><%= #books.book_title %></td>
<td><%= #books.author_name %></td>
<td><%= #books.publisher_name %></td>
<td><%= #books.edition %></td>
<td><%= #books.pages %></td>
<td><%= #books.date_of_purchase %></td>
<td><%= image_tag("/assets/1.png") %></td>
<td><%= link_to(
image_tag(
"/assets/logout.png",
:alt => "image", :width => 40, :height => 40, :title => "Delete item"
),
homes_remove_path(:id => #books.id),
:method => :delete, :confirm => "Are you sure to remove this?") %>
</td>
</tr>
</table>
<% end %>
</div>
</div>
controller/homes_controller.rb
class HomesController < ApplicationController
before_filter :authenticate_admin!,only: [:admin]
def index
end
def admin
end
def managebooks
#books=Book.new
if params[:id]
#books=Book.all
end
end
def savebooks
#books=Book.new(params[:books])
if #books.save
flash[:notice]="Data has submitted successfully"
flash[:color]="valid"
redirect_to :action => 'managebooks',:id => #books.id
else
flash[:notice]="Data couldnot submitted successfully"
flash[:color]="invalid"
render 'managebooks'
end
end
def remove
#books=Book.find(params[:id])
#books.destroy
end
end
Change this section of your erb code:
<tr>
<td><%= #books.book_name %></td>
<td><%= #books.book_title %></td>
<td><%= #books.author_name %></td>
<td><%= #books.publisher_name %></td>
<td><%= #books.edition %></td>
<td><%= #books.pages %></td>
<td><%= #books.date_of_purchase %></td>
<td><%= image_tag("/assets/1.png") %></td>
<td><%= link_to(
image_tag(
"/assets/logout.png",
:alt => "image", :width => 40, :height => 40, :title => "Delete item"
),
homes_remove_path(:id => #books.id),
:method => :delete, :confirm => "Are you sure to remove this?") %>
</td>
</tr>
to this:
<% #books.each do |book| %>
<tr>
<td><%= book.book_name %></td>
<td><%= book.book_title %></td>
<td><%= book.author_name %></td>
<td><%= book.publisher_name %></td>
<td><%= book.edition %></td>
<td><%= book.pages %></td>
<td><%= book.date_of_purchase %></td>
<td><%= image_tag("/assets/1.png") %></td>
<td><%= link_to(
image_tag(
"/assets/logout.png",
:alt => "image", :width => 40, :height => 40, :title => "Delete item"
),
homes_remove_path(:id => book.id),
:method => :delete, :confirm => "Are you sure to remove this?") %>
</td>
</tr>
<% end %>
If you look at your method managebooks in homes controller then it creates an array of Book objects if :id is present in params.
NOTE: The above change will again fail since we're using each method on #books, which is not defined for a new Book object if there's no :id in params.

Strong Params Unpermitted parameters

I know there are alot of questions on this, but after looking at about a dozen or so none of them appear to be the same problem. I have an "Action" model that I am just simply trying to edit and update. (fyi, this isn't a nested form, I'm not using devise, and this isn't an activeadmin problem...like virtually all other questions about this topic are). I'm getting
error:
unpermitted parameters: utf8, _method, authenticity_token when I do this.
Action params in Actions_controller:
def action_params
params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
IF I change it to:
params.require(:action).permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
than I get the below error (and I can't find any solution for this):
undefined method `permit' for "update":String
Actions Controller:
def edit
#action = Action.find(params[:id])
#actiontypes = Actiontype.all
#categories = Category.all
#lead_categories = #categories.where(lead: true)
#user = current_user
#reviewer = User.find(#action.reviewer_id) if #action.reviewed?
end
def update
#action = Action.find(params[:id])
if #action.update!(action_params)
binding.pry
flash[:success] = "Loop closed!"
redirect_to '/closingloop/actions?reviewed=false'
else
flash[:danger] = "Something Went Wrong! The loop was not closed!"
render :edit
end
end
def action_params
params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
View:
<%= form_for [:closingloop, #action] do |f| %>
<%= f.hidden_field :reviewer_id, :value => #user.id %>
<%= f.hidden_field :reviewed, :value => true %>
<table width="70%" align="center" class="table table-responsive">
<tr>
<th>Tracking Number</th>
<td><%= #action.company.tracking_phone_number %></td>
</tr>
<tr>
<th>Target Number</th>
<td><%= #action.company.phonenumber %></td>
</tr>
<tr>
<th>Opportunity Name</th>
<td><%= #action.opportunity_name %></td>
</tr>
<tr>
<th>Opportunity Address</th>
<td><%= #action.customer_address %></td>
</tr>
<tr>
<th>Opportunity Phone</th>
<td><%= #action.caller_phone_number %></td>
</tr>
<tr>
<th>Call Recording</th>
<td><%= audio_tag(#action.call_recording_link, controls: true) %></td>
</tr>
<tr>
<th>Duration</th>
<td><%= #action.duration %></td>
</tr>
<tr>
<th>Call Status</th>
<td><%= #action.call_status %></td>
</tr>
<tr>
<th>Date & Time</th>
<td><%= #action.created_at.to_formatted_s(:long) %></td>
</tr>
<% if #action.reviewed? %>
<tr id="row_reviewed_by">
<th>Reviewed By</th>
<td><%= #reviewer.first_name %> <%= #reviewer.last_name %></td>
</tr>
<% end %>
<tr><td colspan="2"> </td></tr>
<tr id="q_call_answered">
<th>Call Answered?</th>
<td>
<div class="radio-toolbar">
<%= f.radio_button :call_answered, true, class: 'call_answered_true' %>
<%= f.label :call_answered, "Yes" %>
<%= f.radio_button :call_answered, false, class: 'call_answered_false' %>
<%= f.label :call_answered, "No" %>
</div>
</td>
</tr>
<tr id="why_not_answered" style="display:none;">
<th>Why wasn't it answered?</th>
<td>
<%= f.select :why, options_for_select([["No Answer", "N"], ["Abandoned", "A"], ["After Business Hours", "H"]], #action.why), { include_blank: true } %>
</td>
</tr>
<tr id="q_opportunity" style="display:none;">
<th>Was it a opportunity?</th>
<td>
<div class="radio-toolbar">
<%= f.radio_button :is_customer, true, class: 'opportunity_true' %>
<%= f.label :is_customer, "Yes" %>
<%= f.radio_button :is_customer, false, class: 'opportunity_false' %>
<%= f.label :is_customer, "No" %>
</div>
</td>
</tr>
<tr id="opportunity_type" style="display:none;">
<th>Opportunity Type</th>
<td>
<%= f.select :actiontype_id, options_from_collection_for_select(#actiontypes, 'id', 'action_type', #action.actiontype_id), { include_blank: true } %>
</td>
</tr>
<tr id="reason_for_call" style="display:none;">
<th>Reason for Call</th>
<td><%= f.select :category_id, options_from_collection_for_select(#categories, 'id', 'reason', #action.category_id), { include_blank: true } %></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Save" id="save" class="btn btn-success" /></td>
</tr>
</table>
<% end %>
The main problem here is that if you have model named 'action', your params by default will be named in the same way, which collides with ActionController default params. The simplest solution is, I guess, renaming your model.

How to make ajax editable cell?

I have this index.html.erb file:
<h3>Pažymiai</h3><br />
Nuo: <%= #begining_of_week = Date.commercial(2011, 48, 1) %>
iki: <%= #end_of_week = Date.commercial(2011, 48, -1) %>
<table class="macs">
<tr>
<th>Vardas, pavardė</th>
<th>Dalykas</th>
<% (#begining_of_week..#end_of_week).each do |d| %>
<th class="calendar"><%= d.day %></th>
<% end %>
</tr>
<% #students.each do |student| %>
<tr>
<td class="name" rowspan="<%= #subjects.count %>"><%=link_to(admin_student_path(student)) do %><%= student.name%><br /> <%= student.surname %><% end %></td>
<% #subjects.each do |subject| %>
<td class="subject"><%=subject.name%></td>
<% (#begining_of_week..#end_of_week).each do |d| %>
<% #mac = Mac.where(:student_id => student.id, :subject_id => subject.id, :date => d) %>
<% if #mac.blank? %>
<td class="calendar_mac" onclick="location.href='<%= new_admin_mac_path %>'"><center>
</center>
<%= link_to 'new_mac', new_admin_mac_path, :remote => true %>
</td>
<% else %>
<% #mac.each do |mac| %>
<td class="calendar_mac" onclick="location.href='<%= edit_admin_mac_path(mac) %>'"><center>
<%= mac.mac%>
<% end %>
<% end %>
</center></td>
<% end %>
</tr>
<% end %>
<% end %>
</table>
How to make if cell is empty to write new value, if cell has value make it editable, when click cell i want a popup window where you could edit or add new element to database. My table looks:
You can try the best in place gem and follow a sample screen cast by ryanb this might help you out

Resources