Creating dynamic links for a HTML email with embedded ruby - html

I have a simple question about links in HTML emails
I am trying to add a simple dynamic link in an HTML email to my site like this
MySite
This fails, but this works
MySite
I am assuming its to do with the embedded ruby but strangely, the links work if I view them on my iphone.
Any thoughts on this?

Stupid me....
I needed to construct the link using the ActionMailer generating URLs instructions, see here http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
My URL is
<%= link_to "View response", notification_micropost_response_url(#micropost, #response) %>
The default host must be first set in the dev and prod environment config files:
Example (development.rb)
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Related

incorporating my html-css design into ruby on rails

I have created a web page template using html,bootstrap and css. Now, I have to see it run in my rails application. Can anyone help me by telling the way to do it step by step? What all things have to be done from the beginning for the same?
Please help!
You should really follow a tutorial about how to create a ruby on rails app to learn all the basics.
Short version: you need
a controller with an action
a route for your action
a html file with the action name
a scss file with your stylesheet
A real basic version of what it could looks like :
config/routes.rb
root :to => "static_pages#home"
app/controller/static_pages_controller.rb
class StaticPagesController < ActionController::Base
def home
end
end
app/views/static_pages/home.html.erb
Hello World
app/views/layout/application.html.erb:
Let the default (it wraps your home.html.erb file and include your application stylesheet)
app/assets/stylesheets/application.scss: It requires your other stylesheets
//= require home
app/assets/stylesheets/home.scss
Puts your style in it

Ruby on rails: convert text with html and rails code

Article in my app has field "body", which contains text with html. For example:
<div class ='skill_pic'>
<img src = "/assets/images/picture_1.png">
</div>
In view I call field "body" that:
<%= raw #article.body %>
In local machine all is ok, but when I deploy my app on production, images don't display right and browser console returns a 404 error.
image_tag in article body can solve my problem, I mean:
<div class ='skill_pic'>
<%= image_tag('images/picture_1.png') %>
</div>
But helper raw can't convert text with html and rails method
Now, I think in three directions:
find right path for images on production
find some helper, which can right convert text with html and rails code
find another solution
I suppose you want to do some kind of mini-CMS. Be careful not letting users fill in data in your database. You get really bad security problems. If user can edit your html, you better use some kind of templating engine like Liquid or markdown.
That being said, you should just not use the asset pipeline for the referenced images. put the images in the public folder instead of the assets folder. The public folder will be available like a web root '/', so without the 'public' in the url.
You could store erb partials like this in your database:
<div class ='skill_pic'>
<%= image_tag('images/picture_1.png') %>
</div>
And render them with ERB in your views:
<%= raw ERB.new(#article.body).result(binding) %>

Get Windows User name in ASP.NET HTML Page

I have an asp.net application and in that I have a html page.
I need to get the Windows username in that html page.
I understand its not possible in normal page.
I need to achieve this without using ActiveX objects.
you will need to create an AJAX call on your page to some WebMethod in your ASP.NET application that call will return you user name.
it basicaly comes down to placeing request to the WebMethod like this
the call below gets data from WebMothod and displays it in the div in the page
$.get('jqueryintro.htm', function (data) {
$('#maindiv').html(data);
});
If you will need more information you can use this page very easy to follow article.
And don't forget to include jQuery ($) in your page
Assuming you have Windows authentication enabled on the site and the user is authenticated you can put this in your ASPX:
<p><%= User.Identity.Name %></p>
The above code embeds the username in the HTML that is sent to the client.
An AJAX request is not required.
Try something like this...
<div runat="server"><%= System.Security.Principal.WindowsIdentity.GetCurrent().Name %></div>
<div runat="server"><%= User.Identity.Name %></div>
<div runat="server"><%= Request.ServerVariables["LOGON_USER"].ToString() %></div>
As long as you are using Windows Auth it should work, otherwise you would just get the account info for whatever IIS is running under.
Any container with runat="server" should work really it doesn't have to be a div.

Link to home page renders blank

In my rails app, I have a link to the root that renders in all browsers as
<html>
<head>
<style type="text/css"></style>
</head>
<body>19</body>
</html>
Server-side I can see all assets getting passed back. For some reason the browser will not display them because if I view page source I can see ALL my markup correctly.
Now if I load or reload the page localhost:3000 normally the page and all assets are displayed correctly. If I simply refresh I get nothing.
The only time this occurs is when I click a link back to the homepage like a href="/".
The behavior does not occur if I hardcode a href="localhost:3000/" but I don't want to do this.
Rails app, Turbolinks, nowhere in code do I use the number 19, rake routes with root GET well-defined, no public/index.html. I suspect something to the degree of caching or turbolinks but I have no clue how to resolve.
Edit: Config/Routes.rb
SCRR::Application.routes.draw do
root 'home#index'
#pages
get 'about' => 'pages#about'
get 'history' => 'pages#history'
get 'links' => 'pages#links'
get 'safety' => 'pages#safety'
get 'membership' => 'pages#membership'
get 'events' => 'events#index'
get 'grand_prix' => 'grand_prix#index'
get 'newsletters' => 'newsletters#index'
end
Edit 2: Chrome Devtools Console Errors
This error is probably more relevant
Resource interpreted as Font but transferred with MIME type application/x-woff: "https://netdna.bootstrapcdn.com/font-awesome/2.0/font//fontawesome-webfont.woff".
jquery-2.1.0.js?body=1:1078
25115 : CS -> BG : FAILED closepopuptoplevel
onloadwff.js:77
From what you've posted, I don't know whether this would be a Rails issue or a browser issue.
I see you've tagged turbolinks, which could be a contributor to the issue; so let's have a look as to what the problem might be for you:
ERB
The ERB code you should use should be the following:
<%= link_to "Home", root_path %>
If you're trying to reference the "home" url directly, there may be an issue with how you're rendering the URL, hence why it won't show. You should ensure you use the path helper as described above.
This should be coupled with the correct routes:
#config/routes.rb
root "home#index"
resources :pages, path: "" do
collection do
get :about
get :history
get :links
get :safety
get :membership
get :events
get :grand_prix
get :newsletters
end
end
Assets
You mention the assets don't render when you refresh the page, this could be an issue with Turbolinks, although I'm not sure
Turbolinks basically just reloads the <body> of the page, leaving the <head> intact. Although this might sound like nothing to do with your issue, perhaps the problem is to do with the way in which Turbolinks is working with your assets
From your edit, it may appear that your assets are not loading correctly, or are at least not being shown correctly.
I hope this helps, I doubt it will give you a constructive answer

Rails default link when using hash sign

I'm working on a Rails project on the file located at myserver/myNewProject/here.html, and when I have an HTML link like
...
it jumps back to my old project at myserver/myOldProject#test. This is not good, since the old project has nothing to do with the new project.
This is probably because I copied over some code from my old project, but I don't know which part is causing this. How can I correct this behavior?
Use the :anchor attribute in the link_to:
<%= link_to('some link', posts_path(:anchor => 'test'))
Will generate a link like:
some link
See the docs for all the options link_to takes:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html