Open rubyeremite opened 8 years ago
I am using gem 'best_in_place', '~> 3.0.1' Show page, showing data. But when click on field to edit, could not able to edit.
Can someone please enlighten to me?
Here is the routes file
namespace :admin do resources :profiles end
Profile.coffee script
jQuery -> $('#profiles').dataTable(); sPaginationType: "full_numbers"; Activating Best In Place _/ *_> $(".best_in_place").best_in_place();**
jQuery -> $('#profiles').dataTable(); sPaginationType: "full_numbers";
*_> $(".best_in_place").best_in_place();**
gemfile
source 'https://rubygems.org' ruby '2.2.3' gem 'rails', '4.2.6' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'paperclip', '~> 4.2.0' gem 'dropzonejs-rails', '~> 0.4.16' gem 'best_in_place', '~> 3.0.1' group :development, :test do gem 'byebug' end group :development do gem 'web-console', '~> 2.0' gem 'spring' end gem 'jquery-datatables-rails' gem 'jquery-ui-rails'
source 'https://rubygems.org' ruby '2.2.3' gem 'rails', '4.2.6' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'paperclip', '~> 4.2.0' gem 'dropzonejs-rails', '~> 0.4.16' gem 'best_in_place', '~> 3.0.1'
group :development, :test do gem 'byebug' end group :development do gem 'web-console', '~> 2.0'
end gem 'jquery-datatables-rails' gem 'jquery-ui-rails'
profile Controller file
class Admin::ProfilesController < ApplicationController before_action :set_profile, only: [:show, :edit, :update, :destroy] rescue_from ActiveRecord::RecordNotFound, with: :index GET /admin/profiles GET /admin/profiles.json def index @profiles = Profile.includes(:place).all end GET /admin/profiles/1 GET /admin/profiles/1.json def show end GET /admin/profiles/new def new @profile = Profile.new end def create @profile = Profile.new(profile_params) respond_to do |format| if @profile.save format.html { redirect_to [:admin, @profile], notice: 'Profile was successfully created.' } format.json { render action: 'show', status: :created, location: @profile } else format.html { render action: 'new' } format.json { render json: @profile.errors, status: :unprocessable_entity } end end end PATCH/PUT /admin/profiles/1 PATCH/PUT /admin/profiles/1.json def update respond_to do |format| if @profile.update(profile_params) format.html { redirect_to [:admin, @profile], notice: 'Profile was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @profile.errors, status: :unprocessable_entity } end end end def set_profile begin @profile = Profile.find(params[:id]) rescue ActiveRecord::RecordNotFound => e redirect_to action: :index end end Never trust parameters from the scary internet, only allow the white list through. def profile_params params.require(:profile).permit(:title, :place_id) end
class Admin::ProfilesController < ApplicationController before_action :set_profile, only: [:show, :edit, :update, :destroy]
def index @profiles = Profile.includes(:place).all
end
def show
def new @profile = Profile.new end def create
@profile = Profile.new(profile_params)
respond_to do |format| if @profile.save format.html { redirect_to [:admin, @profile], notice: 'Profile was successfully created.' } format.json { render action: 'show', status: :created, location: @profile } else format.html { render action: 'new' } format.json { render json: @profile.errors, status: :unprocessable_entity } end end
def update respond_to do |format| if @profile.update(profile_params) format.html { redirect_to [:admin, @profile], notice: 'Profile was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @profile.errors, status: :unprocessable_entity } end end end
def set_profile begin @profile = Profile.find(params[:id]) rescue ActiveRecord::RecordNotFound => e redirect_to action: :index end end
def profile_params params.require(:profile).permit(:title, :place_id) end
profiles/show.html.erb
<%= notice %> Title: <%= best_in_place @profile, :title , :path => [:admin, :profile]%> <%= link_to 'Edit', edit_admin_profile_path(@profile) %> | <%= link_to 'Back', admin_profiles_path %>
<%= notice %>
Title: <%= best_in_place @profile, :title , :path => [:admin, :profile]%> <%= link_to 'Edit', edit_admin_profile_path(@profile) %> | <%= link_to 'Back', admin_profiles_path %>
Try in profiles/show.html.erb: <%= best_in_place([:admin, @Profile], :title) %>
<%= best_in_place([:admin, @Profile], :title) %>
@skladd has the correct answer. should be marked as resolved.
I am using gem 'best_in_place', '~> 3.0.1' Show page, showing data. But when click on field to edit, could not able to edit.
Can someone please enlighten to me?
Here is the routes file
Profile.coffee script
gemfile
profile Controller file
profiles/show.html.erb