Ruby on Rails Tuesday, February 9, 2016


On 10 Feb 2016 00:21, "Ankit Raj" <aktjha@gmail.com> wrote:
>
>
>
> On Wednesday, February 10, 2016 at 12:00:42 AM UTC+5:30, Matt Jones wrote:
>>
>>
>>
>> On Tuesday, 9 February 2016 12:20:37 UTC-6, Ankit Raj wrote:
>>>
>>> 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
>>> https://gist.github.com/aj07/794468a5f6f92ea63dfb
>>>
>>
>> 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 Jones
>
>
>
> 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 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
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3f1aaafa-1976-44df-adcd-4a946982000f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvj7nFhk7ArTbukszThBVTsVoUUrfemkNj%3D0hRx7fBBPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment