Rou

Hello geeks,

Help me in solving following error.

No route matches {:action=>“create_banner_text”,
:controller=>“websites”,
:id=>nil} missing required keys: [:id]

Detail is given on

With Regards,
Ankit R.

On Tuesday, 9 February 2016 12:20:37 UTC-6, Ankit R. wrote:

.html.erb file · GitHub

On line 48 of the template, you have:

create_banner_text_website_path(@website)

The error indicates that @website is nil, so the
create_banner_text_website_path route helper can’t generate a URL.

You didn’t show the controller code, but that’s where I’d recommend you
start looking.

–Matt J.

On 10 Feb 2016 00:21, “Ankit R.” [email protected] wrote:

Help me in solving following error.

No route matches {:action=>“create_banner_text”,
:controller=>“websites”, :id=>nil} missing required keys: [:id]

Detail is given on
.html.erb file · GitHub

On line 48 of the template, you have:

create_banner_text_website_path(@website)

The error indicates that @website is nil, so the
create_banner_text_website_path route helper can’t generate a URL.

You didn’t show the controller code, but that’s where I’d recommend you
start looking.

–Matt J.

my controller code

class WebsitesController < BaseController

Which line of the controller do you think is setting up @website for the
view?

Colin

layout :get_layout, except: [:saved_template]
before_action :load_website
before_action :show_page, only: [:index, :about, :our_work,
:our_impact, :gallery, :get_involved, :find_us, :donate]
def create
redirect_to root_path
end

def save_font
# to update template fonts only and avoid to run unpublished call back
render json: { status: @website.update_columns(update_font_params) ||
@website.errors.full_messages }
end

def saved_template
current_ngo.websites.new(name: params[:template]).save
redirect_to websites_path(template: params[:template]), notice: “Your
layout successfully saved.”
end

def upload_banner_image
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:section]).sub_sections.where(name:
params[:subsection]).take
@sub_section.section_image = params[:banner_image]
if @sub_section.save
render json: {banner_image_url:
s3_uploaded_url(@sub_section.section_image.current_path), success: true
}
else
render json: {banner_image_url: nil, success: false }
end
end
end

def change_color_text
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:section]).sub_sections.where(name:
params[:subsection]).take
@sub_section.text_color = params[:color]
if @sub_section.save
render json: {text_color: @sub_section.text_color, success: true
}
else
render json: {text_color: nil, success: false }
end
end
end

def create_banner_text
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(“home”).sub_sections.where(name:
“banner”).take
@sub_section.contents = params[:banner][“content”]
@sub_section.save
render :layout => false
end
end

def change_section_background
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:page]).sub_sections.where(name:
params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type],
background_color: @sub_section.contents }
@sub_section =
website.sections.find_by_name(params[:page]).sub_sections.where(name:
params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type],
background_color: @sub_section.contents }

def crop_image
@section = Section.find(params[:id])
@section.remote_section_image_url = params[:image_url]
@section.save
render :json => {image_url:
s3_uploaded_url(@section.section_image.current_path(:thumb)) }
end

def permit_section
params.require(:section).permit(:crop_x, :crop_y, :crop_w, :crop_h)
end

def load_website
@website ||= current_ngo.websites.where(name:
params[:template]).first_or_initialize
def site_data_value
end

end

– Ankit raj


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/3f1aaafa-1976-44df-adcd-4a946982000f%40googlegroups.com
.

On Wednesday, February 10, 2016 at 12:00:42 AM UTC+5:30, Matt J.
wrote:

No route matches {:action=>“create_banner_text”, :controller=>“websites”,
The error indicates that @website is nil, so the
create_banner_text_website_path route helper can’t generate a URL.

You didn’t show the controller code, but that’s where I’d recommend you
start looking.

–Matt J.

my controller code

class WebsitesController < BaseController
layout :get_layout, except: [:saved_template]
before_action :load_website
before_action :show_page, only: [:index, :about, :our_work,
:our_impact,
:gallery, :get_involved, :find_us, :donate]

def index; end
def about; end
def our_work; end
def our_impact; end
def gallery; end
def get_involved; end
def find_us; end
def donate; end

def create
redirect_to root_path
end

def save_font
# to update template fonts only and avoid to run unpublished call
back
render json: { status: @website.update_columns(update_font_params)
||
@website.errors.full_messages }
end

def saved_template
current_ngo.websites.new(name: params[:template]).save
redirect_to websites_path(template: params[:template]), notice:
“Your
layout successfully saved.”
end

def upload_banner_image
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:section]).sub_sections.where(name:
params[:subsection]).take
@sub_section.section_image = params[:banner_image]
if @sub_section.save
render json: {banner_image_url:
s3_uploaded_url(@sub_section.section_image.current_path), success: true
}
else
render json: {banner_image_url: nil, success: false }
end
end
end

def change_color_text
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:section]).sub_sections.where(name:
params[:subsection]).take
@sub_section.text_color = params[:color]
if @sub_section.save
render json: {text_color: @sub_section.text_color, success:
true }
else
render json: {text_color: nil, success: false }
end
end
end

def create_banner_text
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(“home”).sub_sections.where(name:
“banner”).take
@sub_section.contents = params[:banner][“content”]
@sub_section.save
render :layout => false
end
end

def change_section_background
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:page]).sub_sections.where(name:
params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type],
background_color: @sub_section.contents }
else
render :json => { success: false }
end
end
end

#A method for updating the icons of subsections
def change_subsection_icon
website = Website.find(params[:id])
if website
@sub_section =
website.sections.find_by_name(params[:page]).sub_sections.where(name:
params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type],
background_color: @sub_section.contents }
else
render :json => { success: false }
end
end
end

def edit_banner
@website = Website.find(params[:id])
@section = @website.sections.find_by_name(“home”)
end

def crop_image
@section = Section.find(params[:id])
@section.remote_section_image_url = params[:image_url]
@section.save
render :json => {image_url:
s3_uploaded_url(@section.section_image.current_path(:thumb)) }
end

private

def check_mysite
redirect_to root_path unless current_ngo.mysite
end

def get_layout
“#{@website.name}_layout”
end

def permit_section
params.require(:section).permit(:crop_x, :crop_y, :crop_w, :crop_h)
end

def load_website
@website ||= current_ngo.websites.where(name:
params[:template]).first_or_initialize
@section = @website.sections.find_by_name(page)
end

def show_page
@site_data = ParseNgoData.new(session[:ngo_id], page).to_json
# render json: @site_data
# return
render template: “#{@website.name}/#{page}”
end

def site_data_value
@site_data
end
helper_method :site_data_value

def page
params[:action].eql?(“index”) ? ‘home’ : params[:action]
end

def update_font_params
params.permit(:title_font, :sub_title_font, :text_font)
end

end

– Ankit raj

On Tuesday, 9 February 2016 18:21:15 UTC-6, Ankit R. wrote:

On line 48 of the template, you have:

my controller code

[snip]

def load_website
@website ||= current_ngo.websites.where(name:
params[:template]).first_or_initialize

Looks like I misinterpreted your error in my original reply. This line
is
the issue. If the call to first_or_initialize returns an unsaved
object,
then a route like

resources :websites, only: [:index, :create] do
  member do
    get :create_banner_text

isn’t going to be able to generate a URL, since the unsaved object
doesn’t
have an ID.

–Matt J.