controller - Setting rails routes to url path -


i'm new rails , having problems routes. when link gets submitted, should go 'http://example.com' although goes localhost:3000/links/www.example.com running ruby 3.2.8 , ruby1.9.3p194. not sure how info needed. here's it's at. in view have:

<p> <h1><%= @link.title %></h1> <%= link_to @link.url, @link.url %><br />  <p>posted by: <% @link.user %> @ <%= @link.created_at %></p> </p> 

my controller set as:

class linkscontroller < applicationcontroller   def show     @link = link.find(params[:id])   end      before_filter :authenticate_user!    def new        @link = link.new   end    def create      @link = link.new(params[:link])       respond_to |format|          if @link.save           format.html { redirect_to @link, notice: 'link  created.' }           format.json { render :json => @link, status: :created, location: @link }         else           format.html { render :action => "new" }           format.json { render :json => @link.errors, :status => :unprocessable_entity }         end      end   end end   

in development.rb file have:

config.action_mailer.default_url_options = { :host => 'localhost:3000' } 

and routes are:

resources :pages  resources :links  root :to => "pages#index" 

after countless searches, i've had no luck since beginner. suggestions how reset link paths appreciated.

there nothing routes or rails here.

you need output http:// in front of links, if want link off-site. either enter in in textbox when submit link, or modify code conditionally prepend it:

<% link_href = @link.url %> <% link_href = "http://#{link_href}" unless link_href.match(/^https?:\/\//) %> <%= link_to @link.url, link_href %><br /> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -